Created
February 22, 2025 13:44
-
-
Save lalitsingh24x7/1096dde8bb4da016e3cd8dcd36a80a01 to your computer and use it in GitHub Desktop.
get the fie name from lambda event
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
| def handler(event, context): | |
| print("Received event: " + str(event)) | |
| try: | |
| # Extract the file name from the event data | |
| file_name = event['Records'][0]['s3']['object']['key'] | |
| print("File name: " + file_name) | |
| except (KeyError, IndexError) as e: | |
| print(f"Error extracting file name: {e}") | |
| return { | |
| 'statusCode': 400, | |
| 'body': f"Error extracting file name: {e}" | |
| } | |
| # Add your additional processing logic here | |
| return { | |
| 'statusCode': 200, | |
| 'body': 'Hello from Lambda!' | |
| } | |
| """ | |
| { | |
| 'Records': [ | |
| { | |
| 'eventVersion': '2.1', | |
| 'eventSource': 'aws:s3', | |
| 'awsRegion': 'ap-south-1', | |
| 'eventTime': '2025-02-22T10:58:12.860Z', | |
| 'eventName': 'ObjectCreated:Put', | |
| 'userIdentity': { | |
| 'principalId': 'A3GO63IW3SK' | |
| }, | |
| 'requestParameters': { | |
| 'sourceIPAddress': '122.161.50.39' | |
| }, | |
| 'responseElements': { | |
| 'x-amz-request-id': 'GND5HND', | |
| 'x-amz-id-2': 'cZ7WN2hw7ks8f1CgpPIgYsHjmwiYTAV0RjjpczHGfkQr0ks38Gpc8USxe4WvokEXIkNOsNi4=' | |
| }, | |
| 's3': { | |
| 's3SchemaVersion': '1.0', | |
| 'configurationId': 'tf-s3-lambda-20250222105609036700000001', | |
| 'bucket': { | |
| 'name': 'my-lambda-trigger-bucket-2025', | |
| 'ownerIdentity': { | |
| 'principalId': 'A3GO63CAEIW3SK' | |
| }, | |
| 'arn': 'arn:aws:s3:::my-lambda-trigger-bucket-2025' | |
| }, | |
| 'object': { | |
| 'key': 'address.pdf', | |
| 'size': 14714, | |
| 'eTag': '67f0d0cfa2726b34e7b2', | |
| 'sequencer': '0067BC0B60C37' | |
| } | |
| } | |
| } | |
| ] | |
| } | |
| """ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment