Gupta Eman
Gupta Eman

Reputation: 1

Finding the SQS Name which have triggered Lambda Function

I'm looking for a way where we can find the SQS Name through which the Lambda is triggered.

Use Case :

I have 2 SQS Queue (SQS Name ABC and XYZ) and I want to subscribe both the queues to the Single Lambda Function and perform different action (Eg. Inserting the message in DDB Tables) according to the Queue from which the message is coming.

Eg. If message is coming from Queue Name - ABC then it should insert into DDB1 Dynamo Table else if the message is from Queue Name - XYZ then insert into DDB2 Table.

Currently we have set DDB1 value as a environment variable for Lambda and if the message is coming from XYZ then it should be overwritten to DDB2 value.

Thanks for the help in advance, and apologies if the question framing sentence is not correct :)

Upvotes: 0

Views: 1709

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269091

Here is a sample message that Amazon SQS will send to an AWS Lambda function. In fact, I extracted this from the Test function within Lambda:

{
  "Records": [
    {
      "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
      "receiptHandle": "MessageReceiptHandle",
      "body": "Hello from SQS!",
      "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "1523232000000",
        "SenderId": "123456789012",
        "ApproximateFirstReceiveTimestamp": "1523232000001"
      },
      "messageAttributes": {},
      "md5OfBody": "7b270e59b47ff90a553787216d55d91d",
      "eventSource": "aws:sqs",
      "eventSourceARN": "arn:aws:sqs:ap-southeast-2:123456789012:MyQueue",
      "awsRegion": "ap-southeast-2"
    }
  ]
}

There is a field called eventSourceARN that will provide the ARN of the SQS Queue that triggered the function.

Upvotes: 5

Related Questions