Set up pipeline

Let’s go through the instructions to set up CI/CD pipeline using AWS SAM.

  1. In the terminal tab, enter cd ~/environment/api.
  2. Entersam pipeline init --bootstrap.
  3. Enter 1 to select an AWS Quick Start Pipeline templates.
  4. Enter 4 for CodePipeline.
  5. Enter y when prompted to go through the setup process.

Now let’s create Stage 1.

  1. Enter dev for Stage name.
  2. Enter 2 for named profile.
  3. Enter Return key to select the default region.
  4. Enter Return key to create a new pipeline user.
  5. Enter Return key to create a new pipeline execution role.
  6. Enter Return key to create a new CloudFormation execution role.
  7. Enter Return key to create a new artifact bucket.
  8. Enter Return key to selet the default that specifies no IMAGE type lambdas.
  9. Enter Return key to confirm the values.
  10. Enter y key to proceed with creation.

This will kick off an AWS CloudFormation template in the background with the resources needed to set up the dev pipeline for us. PLEASE NOTE: This part will take ~ 2 minutes to complete.

Now let’s continue to create Stage 2.

  1. Enter y when prompted to go through the setup process.
  2. Enter prod for Stage name.
  3. Enter 2 for named profile.
  4. Enter Return key to select the default region.
  5. Enter Return key to create a new pipeline execution role.
  6. Enter Return key to create a new CloudFormation execution role.
  7. Enter Return key to create a new artifact bucket.
  8. Enter Return key to selet the default that specifies no IMAGE type lambdas.
  9. Enter Return key to confirm the values.
  10. Enter y key to proceed with creation.

This will kick off another AWS CloudFormation template in the background with the resources needed to set up the prod pipeline for us. PLEASE NOTE: This part will take ~ 2 minutes to complete.

The console will output the details of the Pipeline IAM user. This will be used to connect the pipeline to be able to deploy the solution.

SAM pipeline IAM user details

Let’s continue creating the pipeline.

  1. Enter 2 to select CodeCommit as the Git provider.
  2. Enter api for the repository name (we will create this repository on our next step).
  3. Enter Return key to select the default branch name main.
  4. Enter Return key to select the default path for template.yaml file.
  5. Enter 1 to select dev as Stage 1.
  6. Enter api-dev-stack for stack name for Stage 1.
  7. Enter 2 to select dev as Stage 2.
  8. Enter api-prod-stack for stack name for Stage 2.

Let’s look at what happened.

First, the sam pipelines created 2 CloudFormation stacks for us, one for each stage, to create the necessary security plumbing as well as buckets to upload artifacts to. The configuration is stored in .aws-sam/pipeline/pipelineconfig.toml file. Feel free to browse through this file to understand how it is all set up. NOTE: if you can’t see the api/.aws-sam/ folder, please click the gear icon at the top right corner of the file navigation pane, and select Show Hidden Files option.

SAM Pipeline artifacts

Second, it creates a api/pipeline/ folder with the build specification that will be used to build, test and deploy the solution. Feel free to browse through the files to understand how it is all set up.


Next, let’s upload our code to the repository.