This project is a simplistic implementation of Lambda backed REST api to be deployed via GitHub Action and CDK (Typescript)
This library is licensed under the MIT-0 License. See the LICENSE file.
Before proceeding further please read and README.md in aws-cross-account-cicd-git-actions-prereq and carry out the deployment steps specified.
Before you checkin the code in this repo into your own git repo, you will need to make updates as shown below. Replace the
<target-account-id>
in parameterCFN_EXECUTION_ROLE
insrc/params/cdk_stack_param.json
file with AWS account id of your designated deployment target account. This parameter represets the iam role that would be assumed by CDK to carryout deployment. You may get the full value of parameterCFN_EXECUTION_ROLE
from Cloudformation output exportGIT-ACTIONS-CF-EXECUTION-ROLE-ARN
of stack deployed in Prerequisite.
Project has been structured such that the API stack has its own folder under root folder
src/
src/git-action-demo-api-stack
deploys AWS resources associated with Git Action Demo API.src/params/cdk_stack_param.json
parameter fileStack specific folder has following components
/lambda
folder which holds individual lambda functions implemented as part of the API.cdk_stack.ts
representing CDK stack for Lambda, API Gateway and associated resourcesThe stack ties into
app.ts
at root folder location which represents CDK app.
The project is to be deployed as a whole app using GitAction workflows defined under
.github/workflows
folder. Each workflow has its own.yml
file whose name is in the formatcicd-workflow-<region>.yml
. The single workflow handles deployment to a specific region that is mentioned in its name. For e.g.cicd-workflow-us-east-1
deploys to us-east-1 region.Workflow has following set of steps.
- Workflow is triggered when code is pushed to a specific branch in the repo.
- Checks out latest version of code.
- Configures AWS credentials using Tools Account Access Key and Secret to assume the Cross Account Role for deployment.
- Installs prerequisits such as CDK
- Builds and deploys cdk stacks using
deploy.sh
script provided at the root of the project folder.The
deploy.sh
script takes following deployment steps
- Install npm packages.
- Transpile code into javascript in
dist
folder.- Package .js files into zip
- Uses CDK CLI commands to first bootstrap CDK app and then deploy it. To manually deploy using script directly, we need to set up default profile for TARGET aws account and then run deploy.sh.