Example 3: Create a GitHub Pipeline with AWS CloudFormation - CodePipeline

Example 3: Create a GitHub Pipeline with AWS CloudFormation

This walkthrough shows you how to use the AWS CloudFormation console to create infrastructure that includes a pipeline connected to a GitHub source repository. In this tutorial, you use the provided sample template file to create your resource stack, which includes your artifact store, pipeline, and change-detection resource (your webhook). After you create your resource stack in AWS CloudFormation, you can view your pipeline in the AWS CodePipeline console. The pipeline is a two-stage pipeline with a GitHub source stage and a CodeDeploy deployment stage.

We strongly recommend that you use AWS Secrets Manager to store your credentials. If you use Secrets Manager, you must have already configured and stored your secret parameters in Secrets Manager. This example uses dynamic references to AWS Secrets Manager for the GitHub credentials for your webhook. For more information, see Using Dynamic References to Specify Template Values.

Important

When passing secret parameters, do not enter the value directly into the template. The value is rendered as plaintext and is therefore readable. For security reasons, do not use plaintext in your AWS CloudFormation template to store your credentials.

Prerequisites:

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

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

  • Choose one of these links to download the sample AWS CloudFormation template file for creating a pipeline: YAML | JSON

    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 CodeDeploy application.

    2. In BetaFleet, enter the name of your 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 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.