https://github.com/poboisvert/serverlessaws
[Python/API] A boilerplate to deploy API (dev, Staging and prod) on a AWS SAM (Serverless) service
https://github.com/poboisvert/serverlessaws
api aws fastapi serverless
Last synced: 8 months ago
JSON representation
[Python/API] A boilerplate to deploy API (dev, Staging and prod) on a AWS SAM (Serverless) service
- Host: GitHub
- URL: https://github.com/poboisvert/serverlessaws
- Owner: poboisvert
- License: mit
- Created: 2022-01-30T03:25:03.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-01T12:49:31.000Z (about 4 years ago)
- Last Synced: 2025-01-07T11:25:05.151Z (about 1 year ago)
- Topics: api, aws, fastapi, serverless
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AWS SAM Template
A simple template to deploy an AWS SAM application in three different environments using GitHub Actions.
The template deploys a single AWS Lambda function that returns a random quote from https://api.quotable.io when invoked.
## Setup
### 1. Use this repository as a template
### 2. Create GitHub environments
- development
- stage
- production
### 3. Install AWS SAM CLI
```shell script
$ pip3 install aws-sam-cli
```
### 4. Bootstrap infrastructure
Use [SAM CLI to bootstrap](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-pipeline-bootstrap.html) required infrastructure resources.
It would be preferable to bootstrap the different environments in different AWS accounts,
but for testing purposes they can all be bootstrapped into the same account.
```shell script
$ sam pipeline bootstrap --stage dev
...
The following resources were created in your account:
- Pipeline IAM user
- Pipeline execution role
- CloudFormation execution role
- Artifact bucket
Pipeline IAM user credential:
AWS_ACCESS_KEY_ID: XXXX
AWS_SECRET_ACCESS_KEY: XXXX
$ sam pipeline bootstrap --stage stage
...
$ sam pipeline bootstrap --stage prod
...
```
### 5. Add secrets to GitHub environments
For each environment, add the following secrets:
- **AWS_ACCESS_KEY_ID**: From the credentials shown in the bootstrap output.
- **AWS_SECRET_ACCESS_KEY**: From the credentials shown in the bootstrap output.
- **SAM_BUCKET**: The artifact bucket created for each environment by the bootstrap script.
- **PIPELINE ROLE**: The pipeline execution role created for each environment by the bootstrap script.
- **DEPLOY_ROLE**: The CloudFormation execution role for each environment by the bootstrap script.
> If the bootstraps from step #4 were performed in the same account, only one IAM user will have been created.
> In that case, use the same credentials in all environments.
## Deploy
Deployment to the different environments is handled by two different GitHub Actions workflows.
### 1. Deploy to development
Deployment to development is made by the *DevDeploy* workflow, which can be manually triggered.
### 2. Deploy to stage & production
Deployment to stage and production is made by the *StageProdDeploy* workflow, which is triggered whenever a GitHub release is published.