Reputation: 1385
I have the same codebase (one git repository) that I want to upload to multiple elastic beanstalk environments. Is there a way to do this, and if so how should I set up my repository in such a way that I can push to multiple environments?
The environments are different language versions of the site, that I want to run in different beanstalks. The language is set by the environment parameters.
Upvotes: 19
Views: 9175
Reputation: 482
I did little workaround without having to upload same source code. First I deploy my "main" environment, then I check for its version and finally deploy this version to the second one. Also it can be modified to use different environment based on current git branch.
Example for 2 different environments (apps) using same source code:
My config.yaml
file for "main" environment
branch-defaults:
main:
environment: environ1-prod
dev:
environment: environ1-dev
...
# this deploys environ1 based on config.yaml
eb deploy
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
APP_VERSION="$(eb status | sed -n 's/.*Version: //p')"
if [ "$BRANCH" = "main" ]; then
eb deploy environ2-prod --version $APP_VERSION
elif [ "$BRANCH" = "dev" ]; then
eb deploy environ2-dev --version $APP_VERSION
fi
Upvotes: 0
Reputation: 41180
You can make the eb cli refer to different environments from different branches by adding config like the following to your .elasticbeanstalk/config.yml
file:
branch-defaults:
main:
environment: staging
production:
environment: production
In this example When you run eb deploy
from the "main" branch, it will deploy to your environment named "staging", whereas when you run it from the "production" branch, it will deploy to your environment named "production".
This approach requires each environment have a dedicated branch. To push one branch to multiple environments, you can use @adnan's answer and specify a branch when you use the eb deploy
command:
eb deploy <environment_name>
Upvotes: 16
Reputation: 4252
If you are using git and have a branch for each environment:
git checkout master
eb use <environment-name>
git checkout staging
eb use <environment-name>
git checkout worker
eb use <environment-name>
Then you can simply
eb deploy
Which will deploy to the defined environment for the current branch.
Under the hood this sets the association in /.elasticbeanstalk/config.yml
You can still eb deploy <environment-name>
from any branch though.
Upvotes: 0
Reputation: 6453
If you specify the version label you can use that version in the other eb deploy
commands:
eb deploy my-first-env -l version-1 && eb deploy my-second-env --version version-1
Upvotes: 2
Reputation: 1385
To answer my own question. The AWS EB CLI 3+ has a nice interface to deploy to multiple environments. If you add another environment to your application you can simply deploy by using
eb deploy <environment-name>
Upvotes: 26