Skip to content

Commit 517fe77

Browse files
committed
Initial commit via Backstage
0 parents  commit 517fe77

88 files changed

Lines changed: 3313 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cfnlintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore_checks:
2+
- E3034 # Template too short
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Feature Branch
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- feature/*
7+
- fix/*
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
steps:
17+
- name: Setup job workspace
18+
uses: ServerlessOpsIO/gha-setup-workspace@v1
19+
20+
- name: Setup Python environment
21+
uses: ServerlessOpsIO/gha-setup-python@v1
22+
with:
23+
python_version: '3.13'
24+
25+
- name: Run tests
26+
run: pipenv run test-unit
27+
28+
- name: Assume AWS credentials
29+
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1
30+
with:
31+
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }}
32+
33+
- name: Install AWS SAM
34+
uses: aws-actions/setup-sam@v2
35+
36+
- name: Validate template
37+
run: sam validate --lint
38+
39+
- name: Build deployment artifact
40+
run: sam build
41+
42+
- name: Store artifacts
43+
uses: ServerlessOpsIO/gha-store-artifacts@v1
44+
with:
45+
use_aws_sam: true
46+
47+
deploy:
48+
needs:
49+
- build
50+
51+
environment: production
52+
runs-on: ubuntu-latest
53+
permissions:
54+
id-token: write
55+
contents: read
56+
57+
steps:
58+
- name: Setup job workspace
59+
uses: ServerlessOpsIO/gha-setup-workspace@v1
60+
with:
61+
checkout_artifact: true
62+
63+
- name: Assume AWS credentials
64+
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1
65+
with:
66+
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }}
67+
deploy_aws_account_id: ${{ secrets.DEPLOYMENT_ACCOUNT_ID }}
68+
69+
- name: Deploy via AWS SAM
70+
uses: ServerlessOpsIO/gha-deploy-aws-sam@v1
71+
with:
72+
aws_account_id: ${{ secrets.DEPLOYMENT_ACCOUNT_ID }}
73+
env_json: ${{ toJson(env) }}
74+
vars_json: ${{ toJson(vars) }}
75+
secrets_json: ${{ toJson(secrets) }}

.github/workflows/main.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Main
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
steps:
17+
- name: Setup job workspace
18+
uses: ServerlessOpsIO/gha-setup-workspace@v1
19+
20+
- name: Setup Python environment
21+
uses: ServerlessOpsIO/gha-setup-python@v1
22+
with:
23+
python_version: '3.13'
24+
25+
- name: Run tests
26+
run: pipenv run test-unit
27+
28+
- name: Assume AWS credentials
29+
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1
30+
with:
31+
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }}
32+
33+
- name: Install AWS SAM
34+
uses: aws-actions/setup-sam@v2
35+
36+
- name: Validate template
37+
run: sam validate --lint
38+
39+
- name: Build deployment artifact
40+
run: sam build
41+
42+
- name: Store artifacts
43+
uses: ServerlessOpsIO/gha-store-artifacts@v1
44+
with:
45+
use_aws_sam: true
46+
47+
deploy:
48+
needs:
49+
- build
50+
51+
environment: production
52+
runs-on: ubuntu-latest
53+
permissions:
54+
id-token: write
55+
contents: read
56+
57+
steps:
58+
- name: Setup job workspace
59+
uses: ServerlessOpsIO/gha-setup-workspace@v1
60+
with:
61+
checkout_artifact: true
62+
63+
- name: Assume AWS credentials
64+
uses: ServerlessOpsIO/gha-assume-aws-credentials@v1
65+
with:
66+
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }}
67+
deploy_aws_account_id: ${{ secrets.DEPLOYMENT_ACCOUNT_ID }}
68+
69+
- name: Deploy via AWS SAM
70+
uses: ServerlessOpsIO/gha-deploy-aws-sam@v1
71+
with:
72+
aws_account_id: ${{ secrets.DEPLOYMENT_ACCOUNT_ID }}
73+
env_json: ${{ toJson(env) }}
74+
vars_json: ${{ toJson(vars) }}
75+
secrets_json: ${{ toJson(secrets) }}

.gitignore

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Dev
51+
.mypy_cache/
52+
53+
# pyenv / environments
54+
.python-version
55+
.env
56+
.venv
57+
env/
58+
venv/
59+
ENV/
60+
env.bak/
61+
venv.bak/
62+
63+
# IDE
64+
.settings/
65+
.project
66+
.pydevproject
67+
.vscode/
68+
*.code-workspace
69+
.idea/
70+
71+
# Mac Cruft
72+
.DS_Store
73+
Thumbs.db
74+
75+
# IDE
76+
.vscode
77+
!.vscode/launch.json
78+
!.vscode/tasks.json
79+
80+
# AWS SAM
81+
.aws-sam/

Pipfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[requires]
7+
python_version = "3.13"
8+
9+
[packages]
10+
common = {editable = true, path = "src/common"}
11+
aws-lambda-powertools = "*"
12+
13+
[dev-packages]
14+
boto3-stubs = { extras = ["apigateway", "dynamodb" ], version = "*"}
15+
16+
cfn-lint = "*"
17+
flake8 = "*"
18+
genson = "*"
19+
jsonschema = "*"
20+
json2python-models = "*"
21+
moto = {extras = ["apigateway", "dynamodb"], version = "*"}
22+
mypy = "*"
23+
pylint = "*"
24+
pytest = "*"
25+
pytest-cov = "*"
26+
pytest-flake8 = "*"
27+
pytest-mock = "*"
28+
pytest-mypy = "*"
29+
pytest-pylint = "*"
30+
tox = "*"
31+
32+
[scripts]
33+
test = "pytest -vv --cov src --cov-report term-missing --cov-fail-under 95 tests"
34+
test-unit = "pytest -vv --cov src --cov-report term-missing --cov-fail-under 95 tests/unit"
35+
test-int = "pytest -vv --cov src --cov-report term-missing --cov-fail-under 95 tests/integration"
36+
test-ete = "pytest -vv --cov src --cov-report term-missing --cov-fail-under 95 tests/ete"
37+
flake8 = "pytest -vv --flake8"
38+
pylint = "pytest -vv --pylint"
39+
mypy = "pytest -vv --mypy"
40+

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# backstage / test-api
2+
3+
test test
4+
5+
The full API can be found in the [OpenAPI document](./openapi.yaml).
6+
7+
8+
## Architecture
9+
This is an AWS serverless CRUD API backend service. It is built on top of the following AWS services:
10+
* API Gateway
11+
* Lambda
12+
* DynamoDB
13+
* Cognito (See _Getting Started / API / Authentication and Authorization_ for more)
14+
15+
16+
## New Project Getting Started
17+
This repository was generated from a template intended to get a new API up and running quickly. This section will cover different aspects of the newly created project as well as areas that may need to be modified to meet the specific needs of a new project.
18+
19+
20+
### Database
21+
The database is a DDB table with a primary key composed of a partition key and sort key to form a composite primark key. Both usage of a composite primary key and generically named partition and sort keys were chosen to allow for a variety of different data types to be stored in the table. These keys are:
22+
23+
* Partition Key: `pk`
24+
* Sort Key: `sk`
25+
26+
The starter code assumes the values of _pk_ and _sk_ are the same value and their value is the same as the API's `id` path parameter. When creating new resources the starter code will dynamically create a UUID as the value for `pk` and `sk`.
27+
28+
If you expect to have multiple types of data stored in the same table you should consider using compound key values for _pk_ and _sk_. These are keys where the values are prefixed with a string indicating the data type. For example, prefixing the value with the collection name. eg. _things#1234_. See the _Code_ section for more information on implimenting this.
29+
30+
31+
### Code
32+
When starting a new project the first place to start with adapting the code to meet the needs of a new project is the [`src/common/common/model/things.py`](src/common/common/model/things.py) file. This file contains interfaces for data and DDB table items.
33+
34+
Start by modifying the dataclasses to match the shape of your data. Optionally you can choose to replace that interface with one from another module if you're working with a pre-existing data model. The existing interface definition was chosen simply to make the project work out of the box.
35+
36+
Next, modify the `createKeys()` and `getKeys()` functions as necessary. These functions exist to make working with keys consistent across Lambda functions. If you want to prepend a data type to key values as mentioned in the _Database_ section you can do so here.
37+
38+
39+
### API
40+
This projects provides and OpenAPI document that defines the API. This document is located at [openapi.yaml](./openapi.yaml). This document besides defining the API is also used by the AWS SAM IaC to define the API Gateway resources.
41+
42+
#### Authentication and Authorization
43+
This service is configured to use a pre-existing Cognito User Pool. Clients should obtain a JWT from the Cognito token endpoint using the client's clientId and clientSecret. Each endpoint's scope requirements are defined in the [OpenAPI document](./openapi.yaml).

catalog-info.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
apiVersion: backstage.io/v1alpha1
3+
kind: Component
4+
metadata:
5+
name: test-api
6+
description: test test
7+
annotations:
8+
github.com/project-slug: ServerlessOpsIO/test-api
9+
spec:
10+
type: api
11+
lifecycle: production
12+
owner: group:backstage
13+
system: system:backstage
14+
providesApis:
15+
- resource:test-api
16+
17+
18+
---
19+
apiVersion: backstage.io/v1alpha1
20+
kind: API
21+
metadata:
22+
name: test-api
23+
description: |
24+
Things API
25+
spec:
26+
type: openapi
27+
system: system:backstage
28+
lifecycle: production
29+
owner: group:backstage
30+
definition:
31+
$text: https://github.com/ServerlessOpsIO/test-api/blob/main/openapi.yaml

cfn-parameters.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Hostname": "api.something.sevrerlessops.io",
3+
"DnsZoneId": "/org/dns/ZoneId",
4+
"CognitoUserPoolArn": $secrets.COGNITO_USER_POOL_ARN,
5+
"Domain": "devtools",
6+
"System": "backstage",
7+
"Component": $env.GITHUB_REPOSITORY_NAME_PART_SLUG_CS,
8+
"CodeBranch": $env.GITHUB_REF_SLUG_CS
9+
}

cfn-tags.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"org:domain": "devtools",
3+
"org:system": "backstage",
4+
"org:component": $env.GITHUB_REPOSITORY_NAME_PART_SLUG_CS
5+
}

0 commit comments

Comments
 (0)