Autoscale on AWS with EC2, Python, Flask, and Nginx Part1

Analytics Vidhya
Published in
5 min readNov 21, 2021
Photo by Gabriel Heinzer on Unsplash

AWS Auto Scaling monitors your applications and automatically adjusts capacity to maintain steady, predictable performance at the lowest possible cost.

Imagine going shopping for groceries and the store hands you all the items in just one bag. You’ll have to carry the bag with one hand which weighs more than 5 kgs.

Imagine the same case but where the store gives you the items with the same weight but divided into 3 different bags. Sounds relieving, right?

Similarly, let’s suppose you want to manage large traffic on your site and your hardware resources are fully utilized on the current server and you want to add more hardware on runtime as per the traffic. This is where scaling can be applied. There are many ways scaling can be achieved.

One such way is using AWS Auto Scaling. AWS auto-scaling can help us to increase or decrease the instance as per traffic on our servers.

You may refer to the following link for an in-depth guide to the service:

Points to be covered:

1. Create an EC2 server and access through putty. (Part1)

2. Create Flask app and configure Nginx on EC2 server (Part2)

3. Configure Autoscaling group (Part3)

In our first part, we will create an EC2 instance, Convert the .pem file to a .ppk file with the help of Puttygen and then access our EC2 instance with putty.

Create Ec2 server

Amazon EC2 allows us to create a virtual machine with our choice of hardware and software configuration. Let’s create one.

  • Search for EC2 from the search bar and click on the EC2 service.
  • Click on instances(running).
  • Click on launch instance
  • Let’s select an OS that suits our requirements. For this guide, I’ll go with Ubuntu Server 18.04
  • Now we get options of the instance types. Where we can see how much RAM and vCPU we are going to get. I will go with the t2.micro free tier.
  • Click Next in steps 3,4 and 5 with default configurations. Now on Step 6 Make sure you allow HTTP port by clicking add rule button. The SSH rule allows us to access instances from software like putty. The HTTP rule allows port 80 which will allow internet traffic on our server.
  • In the last step, you can create new key pair or choose an existing one it will help you to access your instance with the SSH rule. Give a name to the key pair file and download this file because you will not get this file again.

Access Instance

  • Now we will access this instance with the help of putty. Putty accepts a .ppk file to connect the server and AWS gives us a .pem file so we have to convert the .pem file into a .ppk file with help of Puttygen.
Open puttygen → Click load button → select the file that you get from AWS → click save private key button → save file as .ppk file.
  • To access the instance through Putty, we require an IP address of our instance. For finding the IP address of the instance select the instance from the EC2 dashboard and go to the details section where we will get the public ipv4 address of our EC2 instance copy this IP address.
  • Open Putty software and paste the public IP address which you got from AWS in hostname.
  • To access the instance we have to provide a private key of our instance for that go to the auth section in putty software and browse the .ppk file that we have just generated from Puttygen tool. Now click on open.
  • If you get any prompt like below accept it.
  • Give your instance username. For most cases, by default, it will be ubuntu.

After we have given the username now we are successfully signed in and we are able to use instance.

That’s all for this part. we will create a Flask server and configure Nginx in the second part. See you soon in the next article.

If you like this post, HIT Buy me a coffee! Thanks for reading.

Your every small contribution will encourage me to create more content like this.



Analytics Vidhya

Howdy & Welcome. I am a content creator, machine learning researcher, and consultant. consultancy: