Last active
July 12, 2022 08:22
-
-
Save srcecde/ecde0052951209731a5ed21079a416e4 to your computer and use it in GitHub Desktop.
AWS: Reading File content from S3 on Lambda Trigger
This file contains hidden or 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 boto3 | |
import urllib | |
def lambda_handler(event, context): | |
s3 = boto3.client("s3") | |
if event: | |
print("Event : ", event) | |
file_obj = event["Records"][0] | |
filename = str(file_obj['s3']['object']['key']) | |
filename = urllib.parse.unquote_plus(filename) | |
print("Filename: ", filename) | |
fileObj = s3.get_object(Bucket = "aws-lambda-trigger", Key=filename) | |
print("File Obj", fileObj) | |
file_content = fileObj["Body"].read().decode('utf-8') | |
print(file_content) | |
return 'Thanks for Watching' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks for sharing the code, but when I am trying to run the same, its not printing the file content, although its printing everything else but not the content. Can you please suggest anything?
Thanks
AF