0% found this document useful (0 votes)
129 views

Deploy Flask App With AWS RDS and ElastiCache Redis

The document discusses deploying a Flask application on AWS using Amazon RDS for the database and Amazon ElastiCache for Redis. It covers launching an Elastic Beanstalk instance, creating security groups, connecting the instances, and modifying local files. The goal is to replace local Docker containers with scalable, fault-tolerant AWS managed services for production.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views

Deploy Flask App With AWS RDS and ElastiCache Redis

The document discusses deploying a Flask application on AWS using Amazon RDS for the database and Amazon ElastiCache for Redis. It covers launching an Elastic Beanstalk instance, creating security groups, connecting the instances, and modifying local files. The goal is to replace local Docker containers with scalable, fault-tolerant AWS managed services for production.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Deploy Flask app with AWS

RDS and ElastiCache Redis

Deploy Flask app with AWS RDS and ElastiCache Redis


Previous Project
- In the previous project, we understood about

- Nginx-uWSGI-Flask

- PostgreSQL and SQLAlchemy

- Redis

- Using docker-compose to network between three docker containers

- Translating docker-compose specifications into Dockerrun.aws.json

- Deploying this multi-container application onto AWS Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


HANDS-ON
- It is a good practice to separate resource credentials from the actual application

- In the previous project, let us db and redis credentials to environment variables in


local code.

Deploy Flask app with AWS RDS and ElastiCache Redis


Problem?

- Custom containers by docker-compose are fine for small applications.

- But in enterprise level, the apps should be:

- Highly available to users

- Fault-tolerant to make sure apps are always up and live

- Scalable to meet the growing demands of users

- We need manageable distributed infrastructure

Deploy Flask app with AWS RDS and ElastiCache Redis


Solution

- Use cloud products provided by cloud platforms like AWS.


- These cloud products are Automated managed services.
- Further, we could configure them to be
- Scalable
- Fault-tolerant
- Highly-available
- Most of the products are pay-as-you-go

Deploy Flask app with AWS RDS and ElastiCache Redis


What are we going to do?

- We will replace:

- The database service container with AWS RDS

- The redis service container with AWS ElastiCache

Amazon RDS Amazon ElastiCache

Deploy Flask app with AWS RDS and ElastiCache Redis


What is AWS RDS?
- Amazon Relational Database Service
- RDS supports several database instance types like PostgreSQL, MySQL, MariaDB, etc.
- RDS is a managed service by AWS which is:
- Scalable
- Fault-tolerant
- Highly-available
- Secure
- Allows database setup & backup

Deploy Flask app with AWS RDS and ElastiCache Redis


What is AWS ElastiCache
- Fully managed in-memory data store, compatible with Redis or Memcached
- Powers real-time applications with sub-millisecond latency
- Popular choice for real-time use cases like:
- Caching

- Session Stores

- Real-Time Analytics, etc.

Deploy Flask app with AWS RDS and ElastiCache Redis


DB container
Project Architecture

Postgres Server
Web Service Container

NGINX+uWSGI+
Flask Container

Redis Server

Redis Container

Deploy Flask app with AWS RDS and ElastiCache Redis


Networking in docker-compose
- In local, internal networking is setup by Compose for containers to communicate with each
other.
- For example: if the project folder is myapp with following docker-compose file:
version: "3.9"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"

- Upon running docker-compose up, a network named myapp_default is created

Deploy Flask app with AWS RDS and ElastiCache Redis


Networking in docker-compose
- web and db containers join the myapp_default network.

- Now each container is both reachable by other containers on that network


and discoverable by them at a hostname identical to the container name.
- Each container can now look up the hostname web or db
- and get back the appropriate container’s IP address.

- For example, web’s application code could connect to the URL postgres://db:5432 and start
using the Postgres database.

Deploy Flask app with AWS RDS and ElastiCache Redis


Amazon RDS
Project Architecture on AWS Instance

Amazon Elastic Beanstalk Postgres Server

NGINX+uWSGI+
Flask Container

Redis Server

Amazon ElastiCache
Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Networking between AWS Services

- We need to configure the VPC and security groups


- VPC is a service which provides a private and secure space (or network) for the
AWS resources that we want to use.
- We can use the default VPC which is created when we create an AWS account; we
can also create a custom VPC

Deploy Flask app with AWS RDS and ElastiCache Redis


Security Groups
- Further, we configure security groups (to filter traffic) and set environment variables
(to establish connection to instances)
- Security groups provide instance level security for EC2 instances, by restricting port
and protocol access
- Thus security groups acts as firewall for your instance to control inbound and
outbound traffic.
- That is, what traffic to allow to the EC2 instance, and what traffic to go out from the
EC2 instance.
- Since AWS security groups are stateful, we do not need to add rules for return.

Deploy Flask app with AWS RDS and ElastiCache Redis


Networking in Our Project on AWS
Default VPC
database-security-group

RDS
Instance

Elastic
Beanstalk

ElastiCache
Instance
redis-security-group

Deploy Flask app with AWS RDS and ElastiCache Redis


What to do now?

Launch Elastic Beanstalk Instance

Create Security Groups

Launch RDS and ElastiCache Instances

Connect EB to RDS and ElastiCache

Change Local Project files

Push code to GitHub

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch Elastic Beanstalk Instance
Let’s configure Elastic Beanstalk

Deploy Flask app with AWS RDS and ElastiCache Redis


What to do now?

Launch Elastic Beanstalk Instance

Create Security Groups

Launch RDS and ElastiCache Instances

Connect EB to RDS and ElastiCache

Change Local Project files

Push code to GitHub

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Create Security Groups

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


What to do now?

Launch Elastic Beanstalk Instance

Create Security Groups

Launch RDS and ElastiCache Instances

Connect EB to RDS and ElastiCache

Change Local Project files

Push code to GitHub

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch RDS Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

To put screenshots taken on the go

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

to
ge
Chan

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


Launch ElastiCache Instance

Deploy Flask app with AWS RDS and ElastiCache Redis


What to do now?

Launch Elastic Beanstalk Instance

Create Security Groups

Launch RDS and ElastiCache Instances

Connect EB to RDS and ElastiCache

Change Local Project files

Push code to GitHub

Deploy Flask app with AWS RDS and ElastiCache Redis


Connect EB to RDS and ElastiCache

Deploy Flask app with AWS RDS and ElastiCache Redis


Connect EB to RDS and ElastiCache

Deploy Flask app with AWS RDS and ElastiCache Redis


Connect EB to RDS and ElastiCache

Deploy Flask app with AWS RDS and ElastiCache Redis


Connect EB to RDS and ElastiCache

Deploy Flask app with AWS RDS and ElastiCache Redis


Connect EB to RDS and ElastiCache

Deploy Flask app with AWS RDS and ElastiCache Redis

You might also like