AWS CodeDeploy

This page documents deployments using the next major version dpl v2 which currently is in a beta release phase. Please see our blog post for details. The current default version is dpl v1. Check dpl v1 documentation here.

Travis CI can automatically upload your build to AWS CodeDeploy after a successful build.

For a minimal configuration, add the following to your .travis.yml:

deploy:
  - provider: s3
    # rest of S3 deployment for your app
    # ⋮
  - provider: codedeploy
    access_key_id: <encrypted access_key_id>
    secret_access_key: <encrypted secret_access_key>
    bucket: <bucket>
    key: <bucket_key>
    application: <app>
    deployment_group: <deployment_group>

In this example, your code will be deployed to an existing CodeDeploy application called <app> in AWS Region us-east-1.

A complete example can be found here.

Status #

Support for deployments to AWS Code Deploy is *stable**.

Known options #

Use the following options to further configure the deployment.

access_key_id AWS access key — required, secret, type: string
secret_access_key AWS secret access key — required, secret, type: string
application CodeDeploy application name — required, type: string
deployment_group CodeDeploy deployment group name — type: string
revision_type CodeDeploy revision type — type: string, known values: s3, github, downcase: true
commit_id Commit ID in case of GitHub — type: string
repository Repository name in case of GitHub — type: string
bucket S3 bucket in case of S3 — type: string
region AWS availability zone — type: string, default: us-east-1
file_exists_behavior How to handle files that already exist in a deployment target location — type: string, default: disallow, known values: disallow, overwrite, retain
wait_until_deployed Wait until the deployment has finished — type: boolean
bundle_type Bundle type of the revision — type: string
key S3 bucket key of the revision — type: string
description Description of the revision — type: string
endpoint S3 endpoint url — type: string

Shared options #

cleanup Clean up build artifacts from the Git working directory before the deployment — type: boolean
run Commands to execute after the deployment finished successfully — type: string or array of strings

Environment variables #

All options can be given as environment variables if prefixed with AWS_ or CODEDEPLOY_.

For example, access_key_id can be given as

  • AWS_ACCESS_KEY_ID=<access_key_id> or
  • CODEDEPLOY_ACCESS_KEY_ID=<access_key_id>

    Interpolation variables #

The following variables are available for interpolation on description:

  • application
  • bucket
  • bundle_type
  • commit_id
  • deployment_group
  • endpoint
  • file_exists_behavior
  • git_author_email
  • git_author_name
  • git_branch
  • git_commit_author
  • git_commit_msg
  • git_sha
  • git_tag
  • key
  • region
  • repository
  • revision_type
  • build_number

Interpolation uses the syntax %{variable-name}. For example, "Current commit sha: %{git_sha}" would result in a string with the current Git sha embedded.

Furthermore, environment variables present in the current build environment can be used through standard Bash variable interpolation. For example: “Current build number: ${TRAVIS_BUILD_NUMBER}”. See here for a list of default environment variables set.

Securing secrets #

Secret option values should be given as either encrypted strings in your build configuration (.travis.yml file) or environment variables in your repository settings.

Environment variables can be set on the settings page of your repository, or using travis env set:

travis env set AWS_ACCESS_KEY_ID <access_key_id>

In order to encrypt option values when adding them to your .travis.yml file use travis encrypt:

travis encrypt <access_key_id>

Or use --add to directly add it to your .travis.yml file. Note that this command has to be run in your repository’s root directory:

travis encrypt --add deploy.access_key_id <access_key_id>

Waiting for Deployments #

By default, the build will continue immediately after triggering a CodeDeploy deploy. To wait for the deploy to complete, use the wait_until_deployed option:

deploy:
  provider: codedeploy
  # ⋮
  wait_until_deployed: true

Travis CI will wait for the deploy to complete, and log whether it succeeded.

Bundle Types #

The bundleType of your application is inferred from the file extension of key set in your .travis.yml.

If your .travis.yml contains both, and they do not match, set bundle_type explicitly to the correct value.

Specifying the AWS region #

You can explicitly specify the AWS region to deploy to with the region option:

deploy:
  provider: codedeploy
  # ⋮
  region: us-west-1

Pull Requests #

Note that pull request builds skip the deployment step altogether.

See also #