top of page
Image by Pascal Meier

Hosting Deep Learning apps on AWS (Stage 3): Infrastructure as Code (IaC) - Serverless, EC2 & Linux

Updated: May 25


Having successfully deployed a react app to AWS Lambda in Stage 1 and built a local Deep Learning Flask app in Stage 2, we now put these two components together using Serverless as Infrastructure as Code


Here’s the process:


i. Create EC2 instance


In the AWS Console, go to the url below, launch an EC2 (Linux) instance, choosing t3.small rather than t3.micro then create a key pair pem file.


Note that this EC2 machine is not on the free tier (1 GB RAM is definitely not enough!) but it is relatively cheap costing ~ 0.50c per day.


Although t3.small is sufficient for the app, the processor is only 2 GB RAM, so you may want to use a higher grade instance which will of course incur higher charges. For other EC2 instance types see here.


ii. Connect to EC2


After creating your EC2 instance, click on


Instance ID > EC2 Instance Connect tab (default) > Connect


to open a Linux window


iii. Create a project folder on EC2 machine


mkdir lambda-dl-aws

iv. Install Git


Still at the project root folder (i.e. the top level), run the command below to install git


sudo yum install git -y # installs git

v. Install serverless


Also run the command below to install serverless in your lambda-dl-aws folder:


curl -o- -L https://slss.io/install | bash

Check serverless is installed by logging out of your EC2 (Linux) instance and reconnecting, then run:


serverless -version

vi. Install Docker


Besides Git, we need to install Docker on the EC2 machine. Run the following one by one in the aws-lambda-dl-app folder:


sudo yum update -y
sudo yum -y install docker
sudo service docker start
sudo usermod -a -G docker ec2-user
exit

Finally close the Linux window and reconnect to your EC2 instance









17 views0 comments

Recent Posts

See All
bottom of page