Skip to content

revanthreddy/codepipeline-bootcamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codepipeline Workshop

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.

Prerequisites

  • AWS CLI
  • default profile has Admin access to the AWS account
  • IDE (Like Pycharm, VS Code)

Run the required setup stack

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

Below resources are created

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

Start the Codepipeline setup in the AWS console

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

Configure the pipeline settings and choose Next.

  • 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)

Source provider – S3

Bucket  – SourceBucket
S3 object key – app.zip
Change detection options – Amazon CloudWatch Events

Configure build project settings and choose Continue to CodePipeline

Project Name - workshop-build (created as part of the stack)

Configure deploy stage settings and choose Next

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

Create Pipeline

Review all the changes and click "Create Pipeline"

Upload code to the SourceBucket (copied from setup stack output)

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>

Challenges

  • Add an approval action in the deploy stage and change the 'runorder' (think cli)

Cleanup

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

Resources

AWS CodePipeline CLI

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published