CircleCI config to deploy to AWS Beanstalk
As part of your build deployment process you can push your current code to AWS Elastic Beanstalk.
Before we start, we’ll need a few steps where we make sure CircelCi has the credentials to push to Elastic Beanstalk,
- Copy your beanstalk ssh key to a string literal:
cat ~/.ssh/eb.key | sed s/$/\\\\n/ | tr -d '\n'
- Paste the resulting output as an environment variable in CircleCI project settings (https://circleci.com/gh/my/repo/edit#env-vars). Ex:
EB_KEY=<output of previous command goes here>
Now we can use that environment variable after the build completes to deploy to EB. Add the following snippets to your circle.yml
file
- First we’ll need to install AWS EB cli tools as part of the test instance setup.
- Under deployment, I first restrict the deploy commands to a specific branch.
- Then we use the environment variable we created earlier to create a key file which the aws eb cli tools will look for to authenticate.
- Then we just deploy the current code using the top commit SHA as the version label. One could possibly even use the tag or a custom label.