Created
November 21, 2021 03:20
-
-
Save meanii/caef4500882ca300ae61cfcac941e071 to your computer and use it in GitHub Desktop.
s3 service triger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
dynamodb = boto3.resource('dynamodb') | |
s3_client = boto3.client('s3') | |
table = dynamodb.Table('customer') | |
def lambda_handler(event, context): | |
# Retrieve File Information | |
bucket_name = event['Records'][0]['s3']['bucket']['name'] | |
s3_file_name = event['Records'][0]['s3']['object']['key'] | |
# Load Data in object | |
json_object = s3_client.get_object(Bucket=bucket_name, Key= s3_file_name) | |
jsonFileReader = json_object['Body'].read() | |
jsonDict = json.loads(jsonFileReader) | |
# Save date in dynamodb table | |
table.put_item( Item=jsonDict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment