DEV Community

Yasunori Tanaka
Yasunori Tanaka

Posted on • Originally published at Medium on

1 2

Create Deploy Pipeline for AWS Elastic Beanstalk App

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.

A deploy pipeline

This project’s directory structure is like this:

my-api
  + .elasticbeanstalk
  | + config.yaml
  + application.py
  + requirements.txt
Enter fullscreen mode Exit fullscreen mode

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:

Source configuration for getting a source from GitHub master branch

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:

Build configuration for unit testing

You need to create buildspec.yaml to run the build step on CodeBuild.

version: 0.2
phases:
pre_build:
commands:
- pip install -r my-api/requirements.txt
build:
commands:
- python -m unittest discover -s my-api
artifacts:
files:
- '**/*'
base-directory: my-api

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:

Deploy configuration for deploying new code to Elastic Beanstalk

So you add a configuration file for Elastic Beans like below:

# You must set this file into .elasticbeanstalk direcotry like this;
# .elasticbeanstalk/config.yaml
branch-defaults:
default:
environment: api-env
environment-defaults:
api-env:
branch: null
repository: null
global:
application_name: my-api
default_ec2_keyname: null
default_platform: python-3.6
default_region: ap-northeast-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: eb-cli
sc: null
workspace_type: Application
view raw config.yaml hosted with ❤ by GitHub

Then you just push your code to GitHub’s master branch, CodePipeline automatically builds it and deploy to Beanstalk.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay