Build the original environment

The first step in the workshop is to deploy our application running on Amazon EC2. Run the commands below and while the build is happening, proceed to the code review section to gain an understanding of what we’re building and deploying.

# Setup virtual environment
cd ~/environment/ecsdemo-migration-to-ecs/build_ec2_environment

virtualenv .env 

source .env/bin/activate

# Install packages
pip3 install -r requirements.txt

# Deploy the environment
cdk deploy --require-approval never

Code Review

We are using the AWS Cloud Development Kit (CDK) to provision our resources for our environment, which we plan to migrate from. The build command is going to provision a VPC, a DynamoDB table, as well as an EC2 instance residing within an Autoscaling group. The application is running as a systemd unit via systemctl, which is configured via a script stored in the user data. This ensures the service is started and enabled every time a new EC2 instance launches.

Let's Dive in
  • Once the deployment is complete, let’s access the EC2 instance and test our application.