Automatic Deployments: Create a CodePipeline

Objective

  • Automatically update our application when a change gets pushed to GitHub.

Steps

  • Create a CodePipeline.

Defining our pipeline

The pipeline comes in three stages:

  1. The Source stage pulls the latest code from GitHub.
  2. The Build stage builds the latest code with CodeBuild according to our buildspec.yml file.
  3. The Deploy stage deploys the build artifacts from CodeBuild to the EC2 instances referenced in the deployment group, and starts the application according to our appspec.yml file.
Press + to interact
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
Name: !Ref AWS::StackName
ArtifactStore:
Location: !Ref CodePipelineBucket
Type: S3
RoleArn: !GetAtt DeploymentRole.Arn
Stages:
- Name: Source
Actions:
- Name: Source
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: 1
Provider: GitHub
OutputArtifacts:
- Name: Source
Configuration:
Owner: !Ref GitHubOwner
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubPersonalAccessToken
PollForSourceChanges: false
RunOrder: 1
- Name: Build
Actions:
- Name: Build
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
InputArtifacts:
- Name: Source
OutputArtifacts:
- Name: Build
Configuration:
ProjectName: !Ref BuildProject
RunOrder: 1
- Name: Staging
Actions:
- Name: Staging
InputArtifacts:
- Name: Build
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CodeDeploy
Configuration:
ApplicationName: !Ref DeploymentApplication
DeploymentGroupName: !Ref StagingDeploymentGroup
RunOrder: 1

Line #25: We don’t need to poll for changes because we’ll set up a webhook to trigger a deployment as soon as GitHub receives a change.

Now, let’s create the webhook that ...

Get hands-on with 1400+ tech skills courses.