AWS Lambda With Amazon S3 Events
Last Updated :
23 Jul, 2025
AWS Lambda and AWS S3 are two important AWS services used by organizations. AWS Lambda is a serverless compute service that executes the code without any management of servers by the user, while AWS S3 is an object-storing service. In this guide, I have first discussed what is AWS Lambda and then I have discussed what the AWS S3 service is. After this, I walked you through the different steps to create a lambda function and execute the lambda function based on any S3 bucket event that occurs.
What is AWS Lambda?
AWS Lambda is a serverless computing service that allows users to execute their code without managing servers. AWS Lambda supports many programming languages, such as Python, Golang, Java, Node.js, etc. Through the AWS Lambda service, users can create their own Lambda function. These Lambda functions can execute based on any specific event occurrence or at any scheduled time or interval. For example, suppose an organization is using many AWS EC2 instances. Some of the EC2 instances are not used for a long period. These unnecessary EC2 instances will incur more costs. So to solve this issue, organizations make their own custom Lambda function that will automatically delete the unused EC2 instances after crossing a certain threshold time. Apart from this, the Lambda function can also automatically scale up or scale down depending on the amount of traffic it receives. In summary, we can say AWS Lambda provides a flexible, cost-effective, and scalable platform to run the code without any server management, which helps in the development of serverless applications on the AWS cloud platform.
What is AWS S3?
AWS S3 is an object storage service that helps in storing and managing data on the AWS cloud platform. S3 buckets are very similar to file and folder systems on the computer. These S3 buckets mainly store images, videos, static websites, and many more. AWS S3 buckets are highly durable. Every S3 bucket has a globally unique name.
The S3 bucket provides many features to manage and organize the data. Some features are:
- S3 allows users to block public access to the S3 buckets.
- It has a versioning feature that allows the storage of multiple versions of an object in the S3 bucket.
- It allows object replication across the region or the same region to ensure high availability of data.
- It is horizontally scaled to handle massive data and requests.
- S3 provides various storage classes, such as S3 Glacier, S3 Standard, S3 Standard IA, and many more. Users can select the storage class as per their requirements.
Pre-requisites
Before moving to next section make sure that you go through these geeks for geeks article to create S3 bucket and IAM role . If you know already how to create S3 bucket and IAM role , then move to next section .
Steps To Execute Lambda Function With Amazon S3 Bucket Events
Step 1: Go to AWS console and search S3 service . Here create a new S3 bucket.

Step 2: Then go to AWS IAM service to create an IAM role for the Lambda . Here attach the S3 full access policy and CloudWatch logs full access policy.

Step 3: Now go to AWS Lambda service , here create a Lambda function. Here i have selected python 3.10 as runtime and also attached the IAM role created in step 2.

Step 4: Now write the code which will get executed on the basis of any S3 event.
import json
def lambda_handler(event, context):
record = event['Records'][0]
event_name = record['eventName']
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
message = f"Event : '{event_name}' . Object '{key}' in bucket '{bucket}'"
print(message)

Step 5: Create a S3 trigger to the Lambda function. Here i have selected the object create event.

Step 6: Now upload any demo file to S3 bucket.

Step 7: Now go to the Lambda function and here click monitor. Then watch the output of the code in the CloudWatch logs.

Conclusion
Here in this guide you have first learned about the AWS Lambda. Then you have learned about AWS S3. After this you have created a S3 bucket, a Lambda function and S3 event trigger. In the Lambda function you have written a python code which will get executed as per the events of S3 bucket. Finally you have observed the output of the Lambda function in the CloudWatch logs.
Similar Reads
DevOps Tutorial DevOps is a combination of two words: "Development" and "Operations." Itâs a modern approach where software developers and software operations teams work together throughout the entire software life cycle.The goals of DevOps are:Faster and continuous software releases.Reduces manual errors through a
7 min read
Introduction
What is DevOps ?DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
10 min read
DevOps LifecycleThe DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
10 min read
The Evolution of DevOps - 3 Major Trends for FutureDevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
7 min read
Version Control
Continuous Integration (CI) & Continuous Deployment (CD)
Containerization
Orchestration
Infrastructure as Code (IaC)
Monitoring and Logging
Microsoft Teams vs Slack Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
4 min read
Security in DevOps