Automating Amazon Web Services(AWS) with Lambda, Python, and Boto3

Adil Shehzad
5 min readJan 29, 2022

Cloud Basics

If we start our journey with cloud computing, the basic definition is accessing storage and computing resources over the internet, simply accessing someone else computer.

Traditionally, Business hosts their application and store their data in the in-house data centers, usually known as on-prem servers. But the issue with in-house data centers is that they are significantly more extensive. It would help if you had a maintenance team to look after your servers by 24 Hours. Due to machines, they generate a lot of heat, so you need to cool it down with many cooling appliances.

In this era, Businesses need a lot of storage and servers to run their applications, and they need to be more focused on the Business than being more concentrated on their on-prem servers. Hence, their public clouds and hybrid cloud deployment models come in. In the Public cloud, you only care about your application, data, and security, where you don’t need to look after the infrastructure to maintain the infrastructure.

Cloud Deployment Models

There are three cloud deployment models.

Public Cloud

In the Public cloud, you can rent or pay as you go, with the cloud resources owned and operated by a third party. The most common public cloud providers are Amazon Web Services, Microsoft Azure, and Google Cloud.

Private Cloud

A private or on-prem cloud refers to cloud computing resources used in-house and exclusively by a single business or organization. The particularity here is that a private cloud can be physically located on the company’s on-site data center.

Hybrid Cloud

The mixture of Public Cloud and Private Cloud is called Hybrid Cloud. The benefit of Hybrid cloud is that you can access both cloud deployment models and share data across them.

Cloud Models

As we learned three cloud deployment models, there are four cloud models: IaaS, PaaS, SaaS, and FaaS. Let us discuss them one by one, and we will be more focused on the Functions as a Service(FaaS), the serverless-based cloud model.

Infrastructure as a Service(IaaS)

In Infrastructure as a Service, you rent IT infrastructure, including Virtual Machine, Storage resource, network, and operating system.

Platform as a Service(PaaS)

Platform as a Service refers to Cloud computing services that provide an on-demand environment for deploying, testing, and delivering software application services. In Platform as a Service, you are more focused on your application than the underlying infrastructure.

Software as a Service(SaaS)

In SaaS, the customer can access all the needed application services over the internet. GSuite, a comprehensive suite of office offerings such as email, worksheets, etc. Gmail is an excellent example of Software as a Service(SaaS).

Backend as a Service(BaaS)

Backend-as-a-Service (BaaS) is a cloud service model in which developers outsource all the behind-the-scenes aspects of a web or mobile application so that they only have to write and maintain the frontend.

Serverless and BaaS are both similar but Baas is not a Serverless Model.

Functions As a Service(FaaS) or Serverless

Serverless or Functions as a Service (FaaS) means that the developer is more focused on the application at the task level than the server level. You don’t need to worry about the operating system or under-going infrastructure on Serverless.

Multi-Tier Architecture

A multi-Tier or N tier program is distributed among three or more separate computers in a distributed network.

  1. Presentation Tier
  2. Logic Tier or processing Tier
  3. Data Tie

Serverless Architecture

A runtime architecture whereby infrastructure is entirely managed by a cloud service provider and resources are dynamically allocated on demand for a given unit of business logic.

Serverless does use servers but the beauty part is that you don't need to b worry about the servers, you don't need to configure the virtual private cloud (VPC) or manage complex routing rules, or networking cable in your basement to present a high performance, cable application. The cloud provider takes care of those details leaving you to more focus on the code.

Serverless benefits

  1. Remove Burden of Infrastructure Management
  2. Built-in Scaling
  3. Reduce operational cost
  4. Simplified Deployment

Serverless Drawbacks

  1. Keep Less used Applications warmed up because Faas applications will be fully stopped if left idle too long.
  2. Multi-tenancy concerns mean data security can be a concern or resources segmentation could be a problem.
  3. Monitoring this application can be complicated.

API Gateway and API Proxy

API Proxy: An HTTP server that allows decoupling from backend service by routing calls to a certain endpoint

API Gateway: An API proxy that provides advanced features such as authentication, input validation, monitoring, and advance request routing.

Understanding AWS Lambda

As a brief overview, AWS Lambda is a function-based computing service that takes the efforts of provisioning and maintaining its infrastructure out of your hands. With Lambda, you don’t need to worry about scaling your infrastructure and removing unnecessary resources as this is all handled for you.

What is Python Boto3?

Boto3 is the Amazon Web Services (AWS) SDK for Python. It enables Python developers to create, configure, and manage AWS services, such as EC2 and S3. Boto3 provides an easy-to-use, object-oriented API, as well as low-level access to AWS services.

Use Case: Automating AWS infrastructure with AWS Lambda and Boto3

Creating Lambda

We need to create Lambda functions, for this go to Lambda and Click on Create Function. In the Permission Assign, the create a new role and we will make changes to this role.

Modifying Policy

To modify Policy, we need to go to the configuration and then from the left menu select the Permission and open the IAM policy to the new tab edit the JSON and add the following JSON code.

Now, go back to the lambda Code editor and add the following code

and Deploy the Lambda Code.

Now go to AWS Ec2 and create an instance for testing, also increase the lambda time so it will execute properly.

Now Go back to the Ec2 and see the Instance machine will be stopped, you can also stop the multiple machines in Multiple Regions.

Session Video Session


In this blog, we learn about the fundamentals of cloud computing and also created and implement a use case for Automating AWS infrastructure using Boto3. If you want to learn more about Serverless, you can check out my following Blog.

You can also reach out to me on LinkedIn.