The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework to define cloud infrastructure in code and provision it through AWS CloudFormation.
The AWS CDK enables you to easily create applications running in the AWS Cloud. But creating the application is just the start of the journey. You also want to make changes to it, test those changes, and finally deploy them to your stack.
The AWS CDK enables this workflow by using the Code* suite of AWS tools: AWS CodeCommit, AWS CodeBuild, AWS CodeDeploy, and AWS CodePipeline.
In this example, We will be building and deploying a Microservice(Api GW/Lambda).Your AWS CDK code and your Lambda code are in the same repository.
The Lambda code is in the lambda directory, while your CDK code is in the bin and lib directories that the cdk init command sets up for your CDK code.
- AWS CLI already configured with Administrator permission
- NodeJS 8.10+ installed
- AWS CDK installed
Creating the Pipeline infrastructure
- Git clone cdk-serverless-pipeline
- Create a CodeCommit repo in your AWS Account.
- Add a
git remoteand point it at the CodeCommit repo above. git pushyour changes to the codecommit repo- Replace
YOUR-CODECOMMIT-REPO-NAMEfrom lib/cdk-serverless-pipeline-stack.ts with the codecommit repository name created above. - Do an
npm installto install Node Dependencies and Build the typescript code usingnpm run build - Deploy the pipeline stack
npm run cdk deploy ServerlessPipelineStack. After the deployment finishes, you should have a three-stage CodePipeline project in your AWS account.
Deploying the changes Try making a change, such as to your lambda-stack.ts AWS CDK code or to your Lambda function code, and push it to the repository. The pipeline should pick up your change, build it, and deploy it automatically, without any human intervention.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilecdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template

