AWS Elastic Beanstalk app can deploy simply by using CodePipeline.
Below is a pipeline I created on CodePipeline for deploying apps to Elastic Beanstalk, S3, and Cloud. I just introduce CodePipeline this time.
This project’s directory structure is like this:
my-api
+ .elasticbeanstalk
| + config.yaml
+ application.py
+ requirements.txt
application.py and requrements.txt are simple Flask app. You can also read a Flask tutorial.
Before creating the deploy pipeline, you need to create your pipeline and Beanstalk app. Please refer to a creating pipeline tutorial and Beanstalk tutorial.
After you create a pipeline and minimal Beanstalk app, you need to set up a source where you get your code from. Below is the example using GitHub:
Next, you need to add a build step to do unit testing or build your app into binary code or archive. And also I specify Output artifacts as “api-artifact”. This is an archived file built in this step to use after steps. In this pipeline, a next deploy step will use this file. Below is my setting:
You need to create buildspec.yaml to run the build step on CodeBuild.
The app is written with Python and include unit tests in a build step, and so add python -m unittest discover -s my-api under the build . A deploy step uses app artifact in the my-api directory, and so you need to base-directory: my-api to create an artifact under the my-api directory.
Next, since we want to deploy the app to Elastic Beanstalk. Below is a deploy step configuration:
So you add a configuration file for Elastic Beans like below:
Then you just push your code to GitHub’s master branch, CodePipeline automatically builds it and deploy to Beanstalk.
Top comments (0)