Menu
AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)

Using the EB CLI with AWS CodeCommit

You can use the EB CLI to deploy your application directly from your AWS CodeCommit repository. With AWS CodeCommit, you can upload only your changes to the repository when you deploy, instead of uploading your entire project. This can save you time and bandwidth if you have a large project or limited Internet connectivity. The EB CLI pushes your local commits and uses them to create application versions when you use eb create or eb deploy.

To deploy your changes, AWS CodeCommit integration requires you to commit changes first. However, as you develop or debug, you might not want to push changes that you haven't confirmed are working. You can avoid committing your changes by staging them and using eb deploy --staged (which performs a standard deployment). Or commit your changes to a development or testing branch first, and merge to your master branch only when your code is ready. With eb use, you can configure the EB CLI to deploy to one environment from your development branch, and to a different environment from your master branch.

Prerequisites

To use AWS CodeCommit with AWS Elastic Beanstalk, you need a local Git repository (either one you have already or a new one you create) with at least one commit, permission to use AWS CodeCommit, and an Elastic Beanstalk environment in a region that AWS CodeCommit supports. Your environment and repository must be in the same region.

To initialize a Git repository

  1. Run git init in your project folder.

    Copy
    ~/my-app$ git init
  2. Stage your project files with git add.

    Copy
    ~/my-app$ git add .
  3. Commit changes with git commit.

    Copy
    ~/my-app$ git commit -m "Elastic Beanstalk application"

Creating an AWS CodeCommit Repository with the EB CLI

To get started with AWS CodeCommit, run eb init. During repository configuration, the EB CLI prompts you to use AWS CodeCommit to store your code and speed up deployments. Even if you previously configured your project with eb init, you can run it again to configure AWS CodeCommit.

To create an AWS CodeCommit repository with the EB CLI

  1. Run eb init in your project folder. During configuration, the EB CLI asks if you want to use AWS CodeCommit to store your code and speed up deployments. If you previously configured your project with eb init, you can still run it again to configure AWS CodeCommit. Type y at the prompt to set up AWS CodeCommit.

    Copy
    ~/my-app$ eb init Note: Elastic Beanstalk now supports AWS CodeCommit; a fully-managed source control service. To learn more, see Docs: https://aws.amazon.com/codecommit/ Do you wish to continue with CodeCommit? (y/n)(default is n): y
  2. Choose Create new Repository.

    Copy
    Select a repository 1) my-repo 2) [ Create new Repository ] (default is 2): 2
  3. Type a repository name or press Enter to accept the default name.

    Copy
    Enter Repository Name (default is "codecommit-origin"): my-app Successfully created repository: my-app
  4. Choose an existing branch for your commits, or use the EB CLI to create a new branch.

    Copy
    Enter Branch Name ***** Must have at least one commit to create a new branch with CodeCommit ***** (default is "master"): ENTER Successfully created branch: master

Deploying from Your AWS CodeCommit Repository

When you configure AWS CodeCommit with your EB CLI repository, the EB CLI uses the contents of the repository to create source bundles. When you run eb deploy or eb create, the EB CLI pushes new commits and uses the HEAD revision of your branch to create the archive that it deploys to the EC2 instances in your environment.

To use AWS CodeCommit integration with the EB CLI

  1. Create a new environment with eb create.

    Copy
    ~/my-app$ eb create my-app-env Starting environment deployment via CodeCommit --- Waiting for application versions to be pre-processed --- Finished processing application version app-ac1ea-161010_201918 Setting up default branch Environment details for: my-app-env Application name: my-app Region: us-east-1 Deployed Version: app-ac1ea-161010_201918 Environment ID: e-pm5mvvkfnd Platform: 64bit Amazon Linux 2016.03 v2.1.6 running Java 8 Tier: WebServer-Standard CNAME: UNKNOWN Updated: 2016-10-10 20:20:29.725000+00:00 Printing Status: INFO: createEnvironment is starting. ...

    The EB CLI uses the latest commit in the tracked branch to create the application version that is deployed to the environment.

  2. When you have new local commits, use eb deploy to push the commits and deploy to your environment.

    Copy
    ~/my-app$ eb deploy Starting environment deployment via CodeCommit INFO: Environment update is starting. INFO: Deploying new version to instance(s). INFO: New application version was deployed to running EC2 instances. INFO: Environment update completed successfully.
  3. To test changes before you commit them, use the --staged option to deploy changes that you added to the staging area with git add.

    Copy
    ~/my-app$ git add new-file ~/my-app$ eb deploy --staged

    Deploying with the --staged option performs a standard deployment, bypassing AWS CodeCommit.

Configuring Additional Branches and Environments

AWS CodeCommit configuration applies to a single branch. You can use eb use and eb codesource to configure additional branches or modify the current branch's configuration.

To configure AWS CodeCommit integration with the EB CLI

  1. To change the remote branch, use the eb use command's --source option.

    Copy
    ~/my-app$ eb use test-env --source my-app/test
  2. To create a new branch and environment, check out a new branch, push it to AWS CodeCommit, create the environment, and then use eb use to connect the local branch, remote branch, and environment.

    Copy
    ~/my-app$ git checkout -b production ~/my-app$ git push --set-upstream production ~/my-app$ eb create production-env ~/my-app$ eb use --source my-app/production production-env
  3. To configure AWS CodeCommit interactively, use eb codesource codecommit.

    Copy
    ~/my-app$ eb codesource codecommit Current CodeCommit setup: Repository: my-app Branch: test Do you wish to continue (y/n): y Select a repository 1) my-repo 2) my-app 3) [ Create new Repository ] (default is 2): 2 Select a branch 1) master 2) test 3) [ Create new Branch with local HEAD ] (default is 1): 1
  4. To disable AWS CodeCommit integration, use eb codesource local.

    Copy
    ~/my-app$ eb codesource local Current CodeCommit setup: Repository: my-app Branch: master Default set to use local sources

Using an Existing AWS CodeCommit Repository

If you already have an AWS CodeCommit repository and want to use it with Elastic Beanstalk, run eb init at the root of your local Git repository.

To use an existing AWS CodeCommit repository with the EB CLI

  1. Clone your AWS CodeCommit repository.

    Copy
    ~$ git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-app
  2. Check out and push a branch to use for your Elastic Beanstalk environment.

    Copy
    ~/my-app$ git checkout -b dev-env ~/my-app$ git push --set-upstream origin dev-env
  3. Run eb init. Choose the same region, repository, and branch name that you are currently using.

    Copy
    ~/my-app$ eb init Select a default region 1) us-east-1 : US East (N. Virginia) 2) us-west-1 : US West (N. California) 3) us-west-2 : US West (Oregon) 4) eu-west-1 : EU (Ireland) 5) eu-central-1 : EU (Frankfurt) 6) ap-south-1 : Asia Pacific (Mumbai) 7) ap-southeast-1 : Asia Pacific (Singapore) 8) ap-southeast-2 : Asia Pacific (Sydney) 9) ap-northeast-1 : Asia Pacific (Tokyo) 10) ap-northeast-2 : Asia Pacific (Seoul) 11) sa-east-1 : South America (Sao Paulo) 12) cn-north-1 : China (Beijing) 13) us-east-2 : US East (Columbus) 14) ca-central-1 : Canada (Central) 15) eu-west-2 : EU (London) (default is 3): 1 ... Note: Elastic Beanstalk now supports AWS CodeCommit; a fully-managed source control service. To learn more, see Docs: https://aws.amazon.com/codecommit/ Do you wish to continue with CodeCommit? (y/n)(default is n): y Select a repository 1) my-app 2) [ Create new Repository ] (default is 1): 1 Select a branch 1) master 2) dev-env 3) [ Create new Branch with local HEAD ] (default is 2): 2

For more information about using eb init, see Configure the EB CLI.