Title: S3 key not in S3 event notification
Tags: amazon-web-services;amazon-s3;aws-lambda;amazon-sqs;amazon-sns
Question: Hello I currently have an event notification set up with my s3 bucket. This notification is sent to a SNS topic, then a SQS Queue, and finally a lambda.
My ultimate goal is for my lambda to read the event notification json and parse out the bucket and key.
The problem is that I see the bucket name in the json but not the key when I print out the 'event' object using python. How/where should I go debug to figure out what is going on? I do remember seeing the key in the json from previous implementations
the json looks like:
'Records': [{
'messageId': '15d42178-c59c-4f3a-8efa-cce8a20acd5b',
'receiptHandle': 'AQEBnPN7q4+jLFQfExOytZYH69w4kvI4ohjJGFqUqOAvCjRHMfbFFvgEeLVjonZ5q4GAYyzLzDSRQmZv3+YTvE3VYqKmU+Nt0rgX824LoMMkKKMuSWBT6c1a0X5dXRJRzFaOKjpniONRg5Gdm1V9I/7mW0x+Zfi0PXr5cQZXVA1NNUdJ4tIkwtpuC+Rh/dbGFQmAo6fQDuCnpzRW1NKGGda440t3ivtUQMvrniwY8ILKVoX9pnS1rAVgVPGBUo8mXyH9ec9p/Er9O9N5Kxc3xQE44MhHUygD1iJbRROBHG9m0Mj6qbKx4uI7S4KQVWRK8hHkxYFUtP4NzhzcGP1LfY91+zG4mNweGzQkfDbvn0LG9+6guxv9dW+uGz1c3f9My7272s+ABfksvfbNRgPSgwJecg==',
'body': '{\n  &quot;Type&quot; : &quot;Notification&quot;,\n  &quot;MessageId&quot; : &quot;78cadcbb-f349-5bae-b39b-85504866b186&quot;,\n  &quot;TopicArn&quot; : &quot;<topic arn&gt;&quot;,\n  &quot;Subject&quot; : &quot;Amazon S3 Notification&quot;,\n  &quot;Message&quot; : &quot;{\\&quot;Service\\&quot;:\\&quot;Amazon S3\\&quot;,\\&quot;Event\\&quot;:\\&quot;s3:TestEvent\\&quot;,\\&quot;Time\\&quot;:\\&quot;2021-10-21T19:01:03.083Z\\&quot;,\\&quot;Bucket\\&quot;:\\&quot;<s3 bucket&gt;\\&quot;,\\&quot;RequestId\\&quot;:\\&quot;TCJP8AZ6S75XXXPN\\&quot;,\\&quot;HostId\\&quot;:\\&quot;VYNq+Jh5Hkg+Vykp2RcIy9lSca7uJyhzLPfE8tcgnt3Je9kH0I+H3zvzvJkd6IvfZKZm2jYqu4Q=\\&quot;}&quot;,\n  &quot;Timestamp&quot; : &quot;2021-10-21T19:01:03.285Z&quot;,\n  &quot;SignatureVersion&quot; : &quot;1&quot;,\n  &quot;Signature&quot; : &quot;EE9xsZx8hezxh8Yhyj8DLc+VSGYowl641kHgqr8tWq2msNwOBv4KEZoTtHJ/hdnfNYLEBsR7imsfv5ZrX7nKRKL2kR8xax57tcih7GRbifIuFyrs9wAhtcuclf2NJQG4eY9OrOHHxPN3fSvNI9xduPeBrxB2TAfbTcWq4AeN0C4KriV18J2dU28ecMJGtmqK0JM+2KLEuwQe/dyYiEnEnWu5EfGweDhYCRvmB1aUPRcW4s3yOHIckklmHhBLkbmufl1me/hdO7GEGa1ju8wJDF33hmmCCSE6M7ITl9niWICBtvWlFz1Md5OiswyriRyN4LZjmvEjzRZtNwy/qMkDYA==&quot;,\n  &quot;SigningCertURL&quot; : &quot;<cert url&gt;&quot;,\n  &quot;UnsubscribeURL&quot; : &quot;<unsubscribe url&gt;&quot;\n}',
'attributes': {
'ApproximateReceiveCount': '34',
'SentTimestamp': <timestamp&gt;,
'SenderId': <senderid&gt;,
'ApproximateFirstReceiveTimestamp': <timestamp&gt;
},
'messageAttributes': {},
'md5OfBody': <md5&gt;,
'eventSource': 'aws:sqs',
'eventSourceARN': <queue-arn&gt;,
'awsRegion': 'us-east-1'

Here is the accepted answer: In your Amazon SNS subscription, activate Amazon SNS raw message delivery.
This will pass-through the S3 Event in a cleaner form, with the body containing a string-version of the JSON from S3. You'll need to use JSON.parse() to convert it to an object.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:10/21/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<amazon-web-services><amazon-s3><aws-lambda><amazon-sqs><amazon-sns>', 'Title': 'S3 key not in S3 event notification', 'ViewCount': 435, 'id': 69668154, 'user_AboutMe': None, 'user_AccountId': 22764735.0, 'user_DisplayName': 'sprint_6', 'user_Reputation': 61.0, 'user_Views': 7.0, 'user_id': 16922964.0}}