horakihor / aws_course

AWS Basic Course for non DevOps Engineers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a demo Python app

The main idea to start this application on EC2 instances and test different AWS services based on it.

Architecture Diagram

Alt text

Setup Application Locally

Prerequisite

MacOS:

Start Application

cd app
make setup
make run POSTGRES_URL="localhost:5432"

Init DB

http://localhost/init

Check App Status

http://localhost

Setup Application EC2 - Manually

Prerequisite

sudo yum -y group install "Development Tools"
sudo yum -y install python3 python3-devel git

Setup PostgreSQL

sudo yum -y install postgresql-server postgresql-contrib postgresql postgresql-devel
sudo postgresql-setup initdb
sudo sed -i 's/peer/trust/g' /var/lib/pgsql/data/pg_hba.conf
sudo sed -i 's/ident/trust/g' /var/lib/pgsql/data/pg_hba.conf
sudo systemctl start postgresql && sudo systemctl enable postgresql

Start Application

sudo git clone https://github.com/horakihor/aws_course.git /opt/aws_course
cd /opt/aws_course/app/
sudo make setup
sudo make run POSTGRES_URL="localhost:5432"

Setup Application EC2 - User Data

We have a few options to setup app with user-data:

  • Local-DB (Setup local PostgreSQL)
  • RDS-DB (Setup Application only)
  • RDS-CloudWatch (Setup Application + CloudWatch Agent)

Put one of the scripts to the User-data field in AWS.

Notes: Change RDS server hostname in user-data script before running.

Lambda & Api Gateway

Local Setup with SAM

pip3 install aws-sam-cli

Start Locally

cd lambda
sam local start-api
curl http://127.0.0.1:3000/

Build and Package

sam build
cd .aws-sam/build/myip
zip -r myip.zip .

Tips

Connect to private network with Bastion host

ssh-agent
ssh-add <key-name>.pem
ssh -A ec2-user@<public-ip of bastion>
ssh <private ip of web server>

Setup CloudWatch logs manully

sudo yum -y install https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws_course/cloudwatch/cloudwatch-logs.json -s

About

AWS Basic Course for non DevOps Engineers


Languages

Language:Shell 75.7%Language:Python 21.6%Language:Makefile 1.3%Language:HTML 1.3%