AWS CodePipeline
User Guide (API Version 2015-07-09)

The procedures in this guide support the new console design. If you choose to use the older version of the console, you will find many of the concepts and basic procedures in this guide still apply. To access help in the new console, choose the information icon.

Tutorial: Create a Pipeline with AWS CloudFormation

The examples use sample templates that allow you to use AWS CloudFormation to create a pipeline that deploys your application to your instances each time the source code changes. The pipeline detects the arrival of a saved change through Amazon CloudWatch Events.

Example 1: Create an AWS CodeCommit Pipeline with AWS CloudFormation

You use a sample template file to create your resource stack, which includes your artifact store, pipeline, and change-detection resources, such as your Amazon CloudWatch Events rule. The pipeline is a two-stage pipeline with an AWS CodeCommit source stage and an AWS CodeDeploy deployment stage.

Prerequisites:

You must have created the following resources to use with the AWS CloudFormation sample template:

  1. Unzip the files from SampleApp_Linux.zip and upload the files into to your AWS CodeCommit repository. You must upload the unzipped files to the root directory of your repository. You can follow the instructions in Step 2: Add Sample Code to Your AWS CodeCommit Repository to push the files to your repository.

  2. Open the AWS CloudFormation console and choose Create Stack.

  3. In Choose a template, choose Upload a template to Amazon S3. Choose Browse and then select the template file from your local computer. Choose Next.

  4. In Stack name, enter a name for your pipeline. Parameters specified by the sample template are displayed. Enter the following parameters:

    1. In ApplicationName, enter the name of your AWS CodeDeploy application.

    2. In BetaFleet, enter the name of your AWS CodeDeploy deployment group.

    3. In BranchName, enter the repository branch you want to use.

    4. In RepositoryName, enter the name of your AWS CodeCommit source repository.

    
            Create a stack for your CodeCommit pipeline
  5. Choose Next. Accept the defaults on the following page, and then choose Next.

  6. In Capabilities, select I acknowledge that AWS CloudFormation might create IAM resources, and then choose Create.

  7. After your stack creation is complete, view the event list to check for any errors.

    Troubleshooting

    The IAM user who is creating the pipeline in AWS CloudFormation might require additional permissions to create resources for the pipeline. The following permissions are required in the IAM user's policy to allow AWS CloudFormation to create the required Amazon CloudWatch Events resources for the AWS CodeCommit pipeline:

    { "Effect": "Allow", "Action": [ "events:PutRule", "events:PutEvents", "events:PutTargets", "events:DeleteRule", "events:RemoveTargets", "events:DescribeRule" ], "Resource": "*" }
  8. Sign in to the AWS Management Console and open the AWS CodePipeline console at https://console.aws.amazon.com/codepipeline/.

    Under Pipelines, choose your pipeline and choose View. The diagram shows your pipeline source and deployment stages.

  9. In your source repository, commit and push a change. Your change-detection resources pick up the change, and your pipeline starts.

Example 2: Create an Amazon S3 Pipeline with AWS CloudFormation

You use a sample template file to create your resource stack, which includes your source bucket, artifact store, pipeline, and change-detection resources, such as your Amazon CloudWatch Events rule. The pipeline is a two-stage pipeline with an Amazon S3 source stage and an AWS CodeDeploy deployment stage.

Prerequisites:

You must have created the following resources to use with the AWS CloudFormation sample template:

Create your pipeline in AWS CloudFormation

  1. Open the AWS CloudFormation console, and choose Create Stack.

  2. In Choose a template, choose Upload a template to Amazon S3. Choose Browse, and then select the template file from your local computer. Choose Next.

  3. In Stack name, enter a name for your pipeline. Parameters specified by the sample template are displayed. Enter the following parameters:

    1. In ApplicationName, enter the name of your AWS CodeDeploy application.

    2. In BetaFleet, enter the name of your AWS CodeDeploy deployment group.

    3. In SourceObjectKey, accept the default for the sample application's zip file. You upload this file to your bucket as soon as the template creates it.

    
            Create a stack for your Amazon S3 pipeline
  4. Choose Next. Accept the defaults on the following page, and then choose Next.

  5. In Capabilities, select I acknowledge that AWS CloudFormation might create IAM resources, and then choose Create.

  6. After your stack creation is complete, view the event list to check for any errors.

    Troubleshooting

    The IAM user who is creating the pipeline in AWS CloudFormation might require additional permissions to create resources for the pipeline. The following permissions are required in the IAM user's policy to allow AWS CloudFormation to create the required Amazon CloudWatch Events resources for the Amazon S3 pipeline:

    { "Effect": "Allow", "Action": [ "events:PutRule", "events:PutEvents", "events:PutTargets", "events:DeleteRule", "events:RemoveTargets", "events:DescribeRule" ], "Resource": "*" }
  7. In the Amazon S3 console for your bucket, choose Upload, and follow the instructions to upload your .zip file.

    Your sample application must remain packaged in a .zip file.

  8. Sign in to the AWS Management Console and open the AWS CodePipeline console at https://console.aws.amazon.com/codepipeline/.

    Under Pipelines, choose your pipeline, and then choose View. The diagram shows your pipeline source and deployment stages.

  9. Complete the steps in the following procedure to create your AWS CloudTrail resources.

Create your AWS CloudTrail resources in AWS CloudFormation

  1. Open the AWS CloudFormation console, and choose Create Stack.

  2. In Choose a template, choose Upload a template to Amazon S3. Choose Browse, and then select the template file for the AWS CloudTrail resources from your local computer. Choose Next.

  3. In Stack name, enter a name for your resource stack. Parameters specified by the sample template are displayed. Enter the following parameters:

    1. In SourceObjectKey, accept the default for the sample application's zip file.

    
            Create a stack for your Amazon S3 AWS CloudTrail resources
  4. Choose Next. Accept the defaults on the following page, and then choose Next.

  5. In Capabilities, select I acknowledge that AWS CloudFormation might create IAM resources, and then choose Create.

  6. After your stack creation is complete, view the event list to check for any errors.

    The following permissions are required in the IAM user's policy to allow AWS CloudFormation to create the required CloudTrail resources for the Amazon S3 pipeline:

    { "Effect": "Allow", "Action": [ "cloudtrail:CreateTrail", "cloudtrail:DeleteTrail", "cloudtrail:StartLogging", "cloudtrail:StopLogging", "cloudtrail:PutEventSelectors" ], "Resource": "*" }
  7. Sign in to the AWS Management Console and open the AWS CodePipeline console at https://console.aws.amazon.com/codepipeline/.

    Under Pipelines, choose your pipeline, and then choose View. The diagram shows your pipeline source and deployment stages.

  8. In your source bucket, commit and push a change. Your change-detection resources pick up the change and your pipeline starts.

Example 3: Create a GitHub Pipeline with AWS CloudFormation

You use a sample template file to create your resource stack, which includes your artifact store, pipeline, and change-detection resource (your webhook). The pipeline is a two-stage pipeline with a GitHub source stage and an AWS CodeDeploy deployment stage.

Prerequisites:

You must have created the following resources to use with the AWS CloudFormation sample template:

  • An AWS CodeDeploy application and deployment group. You can use the AWS CodeDeploy resources you created in Tutorial: Create a Simple Pipeline (AWS CodeCommit Repository).

  • Download the sample AWS CloudFormation template file for creating a pipeline. You can download the sample template in YAML or JSON format. Unzip the file and place it on your local computer.

  • Download the SampleApp_Linux.zip.

  • The GitHub repository and branch you want to use for your source.

  • A personal access key for your GitHub repository. This is used to provide an OAuth token for connection to your repository.

  1. Unzip the files from SampleApp_Linux.zip and upload the files to your GitHub repository. You must upload the unzipped files to the root directory of your repository.

  2. Open the AWS CloudFormation console and choose Create Stack.

  3. In Choose a template, choose Upload a template to Amazon S3. Choose Browse, and then select the template file from your local computer. Choose Next.

  4. In Stack name, enter a name for your pipeline. Parameters specified by the sample template are displayed. Enter the following parameters:

    1. In ApplicationName, enter the name of your AWS CodeDeploy application.

    2. In BetaFleet, enter the name of your AWS CodeDeploy deployment group.

    3. In BranchName, enter the repository branch you want to use.

    4. In GitHubOAuthToken, enter the personal access key for your GitHub repository.

    5. In GitHubOwner, enter the GitHub user name for the owner of the repository.

    6. In GitHubSecret, enter the secret you want to use for the webhook AWS CloudFormation creates.

    7. In RepositoryName, enter the name of your GitHub source repository.

    
            Create a stack for your GitHub pipeline
  5. Choose Next. Accept the defaults on the following page, and then choose Next.

  6. In Capabilities, select I acknowledge that AWS CloudFormation might create IAM resources, and then choose Create.

  7. After your stack creation is complete, view the event list to check for any errors.

  8. Sign in to the AWS Management Console and open the AWS CodePipeline console at https://console.aws.amazon.com/codepipeline/.

    Under Pipelines, choose your pipeline, and then choose View. The diagram shows your pipeline source and deployment stages.

  9. In your source repository, commit and push a change. Your change-detection resources pick up the change and your pipeline starts.