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
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
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.
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.
Creating an AWS CodeCommit Repository with the EB CLI
To get started with AWS CodeCommit, run
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
init, you can run it again to configure AWS CodeCommit.
To create an AWS CodeCommit repository with the EB CLI
eb initin 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
yat the prompt to set up AWS CodeCommit.
eb initNote: 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):
Choose Create new Repository.
Select a repository 1) my-repo 2) [ Create new Repository ] (default is 2):
Type a repository name or press Enter to accept the default name.
Enter Repository Name (default is "codecommit-origin"):
my-appSuccessfully created repository: my-app
Choose an existing branch for your commits, or use the EB CLI to create a new branch.
Enter Branch Name ***** Must have at least one commit to create a new branch with CodeCommit ***** (default is "master"):
ENTERSuccessfully 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
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
Create a new environment with
eb createStarting 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.
When you have new local commits, use
eb deployto push the commits and deploy to your environment.
eb deployStarting 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.
To test changes before you commit them, use the
--stagedoption to deploy changes that you added to the staging area with
git add new-file~/my-app$
eb deploy --staged
Deploying with the
--stagedoption 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
To configure AWS CodeCommit integration with the EB CLI
To change the remote branch, use the
To create a new branch and environment, check out a new branch, push it to AWS CodeCommit, create the environment, and then use
eb useto connect the local branch, remote branch, and environment.
git checkout -b~/my-app$
git push --set-upstream~/my-app$
eb use --source
To configure AWS CodeCommit interactively, use
eb codesource codecommit.
eb codesource codecommitCurrent CodeCommit setup: Repository: my-app Branch: test Do you wish to continue (y/n):
ySelect a repository 1) my-repo 2) my-app 3) [ Create new Repository ] (default is 2):
2Select a branch 1) master 2) test 3) [ Create new Branch with local HEAD ] (default is 1):
To disable AWS CodeCommit integration, use
eb codesource local.
eb codesource localCurrent 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
init at the root of your local Git repository.
To use an existing AWS CodeCommit repository with the EB CLI
Clone your AWS CodeCommit repository.
git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/
Check out and push a branch to use for your Elastic Beanstalk environment.
git checkout -b~/my-app$
git push --set-upstream origin
eb init. Choose the same region, repository, and branch name that you are currently using.
eb initSelect 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):
ySelect a repository 1) my-app 2) [ Create new Repository ] (default is 1):
1Select a branch 1) master 2) dev-env 3) [ Create new Branch with local HEAD ] (default is 2):
For more information about using
eb init, see Configure the EB CLI.