This project contains source code and supporting files to do a workshop on Codepipeline.
The application uses several AWS resources, including Lambda functions and an API Gateway API. These resources are defined in the template.yml
file in this project. You can update the template to add AWS resources through the same deployment process that updates your application code.
- AWS CLI
- default profile has Admin access to the AWS account
- IDE (Like Pycharm, VS Code)
The setup stack creates necessary IAM roles used by Cloudformation, CodeBuild Project and roles, S3 buckets used by Codepipeline during pipeline transitions
Run the below command to create a setup stack at the project root level
$ sh run-setup.sh
Logical ID's | Resource Type |
---|---|
ArtifactBucket | AWS::S3::Bucket |
SourceBucket | AWS::S3::Bucket |
CloudformationLambdaTrustRole | AWS::IAM::Role |
CodeBuild | AWS::CodeBuild::Project |
CodeBuildRole | AWS::IAM::Role |
From your cloudformation console, look at the outputs section of workshop-setup and note down the SourceBucket and ArtifactBucket
Now that all the resources are in place (created by the setup stack), lets use them to create a Codepipeline in the console that will deploy an API Gateway which is backed by a lambda function
- Pipeline name – workshop-pipeline
- Service role – New service role
- Artifact store – Custom location and fill in the 'Bucket' field with ArtifactBucket (created in setup stack)
Bucket – SourceBucket
S3 object key – app.zip
Change detection options – Amazon CloudWatch Events
Project Name - workshop-build (created as part of the stack)
Deploy Provider - AWS Cloudformation
Action mode - Create or update a stack
Stack name - app-stack
Template section
- Artifact Name - BuildArtifact
- File name - package.yml
Role name - <workshop-setup-CloudformationLambdaTrustRole-XXXXXXXXX
Capabilities – CAPABILITY_IAM , CAPABILITY_AUTO_EXPAND
Review all the changes and click "Create Pipeline"
Now that the pipeline is ready to be used we will upload our SAM template to the SourceBucket
sh upload-code-to-s3.sh <SourceBucket>
Once the object (app.zip) is uploaded, go the Codepipeline console and follow the progress. The last stage is the deploy stage where the cloudformation stack is created/updated.
Now Go to CloudFormation console to look at the stack creation process. As the stack creation is complete click on the Outputs section and retrieve the URL of the deployed application.
Make some changes to your code in app/index.js file and re-run the below command and and follow the progress in codepipeline
sh upload-code-to-s3.sh <SourceBucket>
- Add an approval action in the deploy stage and change the 'runorder' (think cli)
To delete the sample application and the bucket that you created, use the AWS CLI.
-
Delete the "workshop-stack" first
-
Empty the SourceBucket and ArtifactBucket manually
-
Then run the below
sh delete-setup.sh
- Delete the pipeline from the Codepipeline console