Aws - Modern Web App Workshop

> AWS (Amazon Web Services)

1 - About

Note about the Aws project Build a Modern Web Application

2 - Steps

git clone -b python
cd aws-modern-application-workshop
:: Taking the python code
git checkout python

2.1 - Create the bucket

aws s3 mb s3://web-app-modern

2.2 - Create a static web hosting with cloudfront

Create a static web hosting with cloudfront from this bucket

  • set the index document
aws s3 website s3://web-app-modern --index-document index.html
  • create an origin access identity and save the id
aws cloudfront create-cloud-front-origin-access-identity --cloud-front-origin-access-identity-config CallerReference=Mysfits,Comment=Mysfits
aws s3api put-bucket-policy --bucket web-app-modern --policy file://module-1/aws-cli/website-bucket-policy.json
aws cloudfront create-distribution --distribution-config file://module-1/aws-cli/website-cloudfront-distribution.json
aws s3 cp module-1/web/index.html s3://web-app-modern/index.html


2.3 - Create the API

2.3.1 - Build the container

  • Docker build that packages a Python flask web app
cd module-2\app
docker build . -t
  • Run it to test
docker run -p 8080:8080 REPLACE_ME_WITH_DOCKER_IMAGE_TAG

2.3.2 - Push the Docker Image to Amazon ECR

  • Creates a new repository in the default AWS ECR registry of the Aws account.
aws ecr create-repository --repository-name mythicalmysfits/service
  • authentication credentials for the Docker client (in order to push container images into the new repository)
aws ecr get-login --no-include-email
:: execute the output
# in bash
$(aws ecr get-login --no-include-email)
  • push the image you created to the ECR repository
  • list the images
aws ecr describe-images --repository-name mythicalmysfits/service

2.3.3 - Create a cluster

aws ecs create-cluster --cluster-name MythicalMysfits-Cluster

2.3.4 - Create a log group

  • Create a new log group in AWS CloudWatch Logs for the container logs to be pushed to. This is especially important when using AWS Fargate since you will not have access to the server infrastructure where your containers are running.
aws logs create-log-group --log-group-name mythicalmysfits-logs

2.3.5 - Register an ECS Task Definition

Register an ECS task definition. Example: register-task-definition

aws ecs register-task-definition --cli-input-json file://module-2/aws-cli/task-definition.json

2.3.6 - Load balancer - Create a Network Load Balancer
aws elbv2 create-load-balancer ^
  --name mysfits-nlb ^
  --scheme internet-facing ^
  --type network ^
> %HOME%/environment/nlb-output.json

Keep the output to extract:

  • the DNSName,
  • VpcId,
  • and LoadBalancerArn - Create a Load Balancer Target Group

Create an NLB target group. You get back a TargetGroupArn.

aws elbv2 create-target-group ^
   --name MythicalMysfits-TargetGroup ^
   --port 8080 ^
   --protocol TCP ^
   --target-type ip ^
   --vpc-id REPLACE_ME_VPC_ID ^
   --health-check-interval-seconds 10 ^
   --health-check-path / ^
   --health-check-protocol HTTP ^
   --healthy-threshold-count 3 ^
   --unhealthy-threshold-count 3 ^
> %HOME%/environment/target-group-output.json - Create A Load Balancer Listener

Create a load balancer listener for the network load balancer

A load balancer listener configure the forwarding of requests received on a specific port to targets that have registered to the target group.

aws elbv2 create-listener ^
  --default-actions TargetGroupArn=REPLACE_ME_NLB_TARGET_GROUP_ARN,Type=forward ^
  --load-balancer-arn REPLACE_ME_NLB_ARN ^
  --port 80 ^
  --protocol TCP

2.4 - Create a service with Fargate


aws ecs create-service --cli-input-json file://module-2/aws-cli/service-definition.json
  • Test the service with the DNS Name of the load balancer. (This Network Load Balancer only supports HTTP ) Example

2.5 - Capture User Behavior

3 - Documentation / Reference