Flask Docker Lab – Lesson 4

Lesson 4 – Cleaning up

Lesson Overview

  • In this lesson we’ll cleaned up our mess

Lesson

  1. Destroy your AWS resource using terraform
    
    
    cd ~/flask_docker_lab/infrastructure/terraform-ecs 
    terraform destroy
    
    
  2. Terminate your EC2 development instance
    The following commands will permanently terminate the EC2 instance in which you run the command. Upon completion of the command, your ssh session will terminate and the EC2 instance will be gone forever

    
    
    export AWS_DEFAULT_REGION=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'` 
    curl -s http://169.254.169.254/latest/meta-data/instance-id | xargs -i aws ec2 terminate-instances --instance-ids {}
    
    

    If you don’t want to destroy the EC2 instance, you can just shut it
    down instead so that it can resumed at a later time using the following
    command. Your account will be charged for the EBS storage volume that
    will remain

    
    
    export AWS_DEFAULT_REGION=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'` 
    curl -s http://169.254.169.254/latest/meta-data/instance-id | xargs -i aws ec2 stop-instances --instance-ids {}
    
    

Lesson Summary

In this lesson we:

  • Un-deployed our docker containers from the cluster
  • Destroyed our resources in AWS using terraform
  • Terminated our developer desktop

Additional Things to try:

  • Expand the flask application to include more containers using micro-services, like the image resizing routine we built for the Flask Lab.
  • Implement auto-scaling policies to automatically grow the number of container instances running our code
  • Connect the containers to a database and practice using environmental variables to point the docker instance to the correct DB, based on the environment its running.