Push to multiple AWS accounts with elastic beanstalk

Posted by Matt Bryson on 11-Sep-2014 19:59:59
Find me on:

UPDATE : EB Cli tools v3 now supports multiple aws profiles

AWS makes it very simple to push to different environments of an application, but what if you need to push to a completely separate AWS account?

It's not really possible, but you can shoehorn it with the following set up....

Say you have 2 branches - stage and production.

stage is set to push to an AWS account in the usual way. The branch is mapped to an EB environment, and you use a .elasticbeanstalk/aws_credential_file file to store your credentials.


Your EB files would look something like this...

[global]
ApplicationName=myApplication
AwsCredentialFile=.elasticbeanstalk/aws_credential_file

DevToolsEndpoint=git.elasticbeanstalk.eu-west-1.amazonaws.com
InstanceProfileName=aws-elasticbeanstalk-ec2-role
Region=eu-west-1
ServiceEndpoint=https://elasticbeanstalk.eu-west-1.amazonaws.com

[branches]
stage=stage-env

[branch:stage]
ApplicationName=myApplication 
EnvironmentName=stage-env


To have another branch push to another account, you will need to create another AWS credentials file, say .elasticbeanstalk/aws_credential_file_production, and then add that to your config.

Clearly, you can only use one at once, so you need to comment / uncomment (with a #) the creds file, when you want to switch between them. You can change other settings as well, such as the ApplicationName.

So, and example config file would be...


"(pushing to a production account)"

[global]
#ApplicationName=myApplication
#AwsCredentialFile=.elasticbeanstalk/aws_credential_file

ApplicationName=myProductionApplication
AwsCredentialFile=.elasticbeanstalk/aws_credential_file_production

DevToolsEndpoint=git.elasticbeanstalk.eu-west-1.amazonaws.com
InstanceProfileName=aws-elasticbeanstalk-ec2-role
Region=eu-west-1
ServiceEndpoint=https://elasticbeanstalk.eu-west-1.amazonaws.com

[branches]
stage=stage-env
production=prod-env

[branch:stage]
ApplicationName=myApplication
EnvironmentName=stage-env

[branch:production]
ApplicationName=myProductionApplication
EnvironmentName=prod-env

Its a bit of hack, but the workflow is;

1) checkout branch
2) swap out the top two lines in the config
3) aws.push as per usual.

For it to work, you DO need to repeat the ApplicationName and EnvironmentName in the [global],[branches] and [branch:*] sections.

To make this a slicker process, ideally you would run git aws.push and pass it the config file to use, but having poked about the ruby files for AWSDevTools, it doesn't look to be an option.

Next step would be to extend the main aws.elasticbeanstalk.push plugin and add it as a command line arg. Thats for another day...

m

Topics: AWS, Deployment, EB (Elastic Beanstalk)

About the author

Matt Bryson is an experienced systems engineer with over 15 years Development and Systems Operations experience.

NEW - Free eBook

Transforming your eDetail process. Click below to download the eBook.

New Call-to-action

Subscribe to Email Updates

Recent Posts