What is AWS Lambda?
AWS Lambda is a compute service that lets you run code without provisioning or managing servers. In essence, this implies that you can develop code in Lambda without having to worry too much about configuring or providing servers or infrastructure.
You can use AWS Lambda to run your code in response to events, such as changes to data in an Amazon S3 bucket or an Amazon DynamoDB table.
Create an AWS Lambda:
- Open the Lambda Console
- Choose Create Function
- Click Create from scratch
- Give your Lambda a name
- Select Python 3.6
- Click Create Function




Provide the Basic information as the Function name, and most especially the run time to select the language used to write your function.






import boto3
from uuid import uuid4
def lambda_handler(event, context):
s3 = boto3.client("s3")
dynamodb = boto3.resource('dynamodb')
for record in event['Records']:
bucket_name = record['s3']['bucket']['name']
object_key = record['s3']['object']['key']
size = record['s3']['object'].get('size', -1)
event_name = record ['eventName']
event_time = record['eventTime']
dynamoTable = dynamodb.Table('newtable')
dynamoTable.put_item(
Item={'unique': str(uuid4()), 'Bucket': bucket_name, 'Object': object_key,'Size': size, 'Event': event_name, 'EventTime': event_time})
Once done, make sure the name for the Dynamo table = “new table” and the Partition key should be Unique and similar to the name of the dynamo table.
Trigger:
Trigger Configuration:






Firstly create a Dynamo DB table.









The information is trigged in dynamo DB which is created through the s3 bucket. Its unique id, bucket, event, event time, object, and will tell the size also.
Conclusion:-
In this blog, we have seen how to set up S3 Trigger with Lambda and DynamodDB in Aws.
To read more about DevOps.
Happy Learning!!
Reference:


