Project5 : Serverless architecture || S3 | DynamoDB || Lambda Function || IAM | AWS project in Hindi

Описание к видео Project5 : Serverless architecture || S3 | DynamoDB || Lambda Function || IAM | AWS project in Hindi

We want to create a Serverless architecture & by using that architecture we want to store in NoSQL database directly from a .csv file. We will be a using a Lambda Function. & that Lambda function will fetch the data from S3(Whenever that .csv file is uploaded) and put the data in the dynamoDB table.

S3, DynamoDB, Lambda Function, IAM, Cloudwatch, eventbridge

SOLUTION-
1. Create a bucket in S3, where we will uploading the .csv file
2. Create a table in dynamoDB, where we will be sending the data(that will be fetched by Lambda)
3. Create a IAM Role and provide the permission to LAMBDA so that Lambda service can go to S3,
DynamoDB & Cloudwatch with FULL ACCESS.
4. We have to write the code in Lambda to perform the task.

--------------------------------------------python code--------------------------------------------------
import json
import boto3

s3_client = boto3.client('s3')
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table('grras_lambda')

def lambda_handler(event, context):
try:

bucket_name = event["Records"][0]["s3"]["bucket"]["name"]
s3_file_name = event["Records"][0]["s3"]["object"]["key"]

response = s3_client.get_object(Bucket=bucket_name, Key=s3_file_name)
data = response["Body"].read().decode('utf-8')
employees = data.split("\n")
for emp in employees:
try:
emp = emp.split(",")
table.put_item(
Item = {
"id": str(emp[0]),
"Name": str(emp[1]),
"City": str(emp[2])
}
)
except:
continue
except Exception as err:
print (err)

return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}


-----------------------------------------------------------------------------------------------------------------------

Thank you
NP.

Комментарии

Информация по комментариям в разработке