Home > Software engineering >  S3 key not in S3 event notification
S3 key not in S3 event notification

Time:10-26

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  "Type" : "Notification",\n  "MessageId" : "78cadcbb-f349-5bae-b39b-85504866b186",\n  "TopicArn" : "<topic arn>",\n  "Subject" : "Amazon S3 Notification",\n  "Message" : "{\\"Service\\":\\"Amazon S3\\",\\"Event\\":\\"s3:TestEvent\\",\\"Time\\":\\"2021-10-21T19:01:03.083Z\\",\\"Bucket\\":\\"<s3 bucket>\\",\\"RequestId\\":\\"TCJP8AZ6S75XXXPN\\",\\"HostId\\":\\"VYNq Jh5Hkg Vykp2RcIy9lSca7uJyhzLPfE8tcgnt3Je9kH0I H3zvzvJkd6IvfZKZm2jYqu4Q=\\"}",\n  "Timestamp" : "2021-10-21T19:01:03.285Z",\n  "SignatureVersion" : "1",\n  "Signature" : "EE9xsZx8hezxh8Yhyj8DLc VSGYowl641kHgqr8tWq2msNwOBv4KEZoTtHJ/hdnfNYLEBsR7imsfv5ZrX7nKRKL2kR8xax57tcih7GRbifIuFyrs9wAhtcuclf2NJQG4eY9OrOHHxPN3fSvNI9xduPeBrxB2TAfbTcWq4AeN0C4KriV18J2dU28ecMJGtmqK0JM 2KLEuwQe/dyYiEnEnWu5EfGweDhYCRvmB1aUPRcW4s3yOHIckklmHhBLkbmufl1me/hdO7GEGa1ju8wJDF33hmmCCSE6M7ITl9niWICBtvWlFz1Md5OiswyriRyN4LZjmvEjzRZtNwy/qMkDYA==",\n  "SigningCertURL" : "<cert url>",\n  "UnsubscribeURL" : "<unsubscribe url>"\n}',
    'attributes': {
        'ApproximateReceiveCount': '34',
        'SentTimestamp': <timestamp>,
        'SenderId': <senderid>,
        'ApproximateFirstReceiveTimestamp': <timestamp>
    },
    'messageAttributes': {},
    'md5OfBody': <md5>,
    'eventSource': 'aws:sqs',
    'eventSourceARN': <queue-arn>,
    'awsRegion': 'us-east-1'
}]

}

CodePudding user response:

In your Amazon SNS subscription, activate Amazon SNS raw message delivery.

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.

  • Related