title: Parse SQS message trigger in AWS Lambda - Python
body: <p>I have a notification on an S3 bucket upload to place a message in an SQS queue. The SQS queue triggers a lambda function. I am trying to extract the name of the file that was uploaded from the SQS message which triggers the lambda function. My SQS event record looks like this when printed to the CloudWatch logs:</p>
  
  <pre><code>{
  "Records": [
      {
          "eventVersion": "2.1",
          "eventSource": "aws:s3",
          "awsRegion": "eu-west-2",
          "eventTime": "2020-04-05T13:55:30.970Z",
          "eventName": "ObjectCreated:Put",
          "userIdentity": {
              "principalId": "A2RFWU4TTDGK95"
          },
          "requestParameters": {
              "sourceIPAddress": "HIDDEN"
          },
          "responseElements": {
              "x-amz-request-id": "024EF2A2E94BD5CA",
              "x-amz-id-2": "P/5p5mDwfIu29SeZcNo3wjJaGAiM4yqBqp4p3gOfLVPeZhf+w5sRjnxsost3BuYub1FVf7tuMFs9KoC98+fwSI9NrT5WbjYq"
          },
          "s3": {
              "s3SchemaVersion": "1.0",
              "configurationId": "ImageUpload",
              "bucket": {
                  "name": "HIDDEN",
                  "ownerIdentity": {
                      "principalId": "A2RFWU4TTDGK95"
                  },
                  "arn": "arn:aws:s3:::HIDDEN"
              },
              "object": {
                  "key": "activity1.png",
                  "size": 41762,
                  "eTag": "9e1645a32c2948139a90e75522deb5ab",
                  "sequencer": "005E89E354A986B50D"
              }
          }
      }
  ]
  }
  </code></pre>
  
  <p>Using this code:</p>
  
  <pre><code>import boto3
  rek = boto3.client('rekognition')
  
  def test(event, context):
      for record in event['Records']:
         print ("test")
         payload=record["body"]
         fullpayload=str(payload)
         print(fullpayload)
  </code></pre>
  
  <p>Using ['s3]['object]['key'] to access the filename 'activity1.png' on the payload string gives me this error:</p>
  
  <pre><code>'s3': KeyError
  Traceback (most recent call last):
  </code></pre>
  
  <p>How can i access the file name from the lambda function?</p>