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_ROLEinsrc/params/cdk_stack_param.jsonfile 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_ROLEfrom Cloudformation output exportGIT-ACTIONS-CF-EXECUTION-ROLE-ARNof 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-stackdeploys AWS resources associated with Git Action Demo API.src/params/cdk_stack_param.jsonparameter fileStack specific folder has following components
/lambdafolder which holds individual lambda functions implemented as part of the API.cdk_stack.tsrepresenting CDK stack for Lambda, API Gateway and associated resourcesThe stack ties into
app.tsat root folder location which represents CDK app.
The project is to be deployed as a whole app using GitAction workflows defined under
.github/workflowsfolder. Each workflow has its own.ymlfile 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-1deploys 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.shscript provided at the root of the project folder.The
deploy.shscript takes following deployment steps
- Install npm packages.
- Transpile code into javascript in
distfolder.- 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.