Unable to send message from API Gateway to FIFO SQS
Asked Answered
C

2

8

I have integrated a API Gateway with FIFO SQS queue using below link https://medium.com/@pranaysankpal/aws-api-gateway-proxy-for-sqs-simple-queue-service-5b08fe18ce50

Below is the snippet of role policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "sqs:SendMessageBatch",
                "sqs:ReceiveMessage",
                "sqs:SendMessage"
            ],
            "Resource": "arn:aws:sqs:*:12345678:Stg"
        }
    ]
}

Whenever is try to test it from API Gateway it throws below error:- "Message": "The request must contain the parameter MessageGroupId."

So I tried to send it via query string but still the error persist.

I have followed the same steps as per the above link for body template and header.

MessageGroupId=098

Simply passing above value in query string and body is below

{"ty":"ui"}
Concuss answered 5/11, 2019 at 13:27 Comment(2)
Can you put the whole code you are using?Anthroposophy
There is no code. My Api Gateway is unable to send message to SQS wit the provided error:- "Message": "The request must contain the parameter MessageGroupId."Concuss
A
19

You need to add MessageGroupId, and MessageDeduplicationId to the URL Query String Parameters in Method Execution. Same way you did for MessageBody.

You'll also need to add MessageGroupId, and MessageDeduplicationId to Integration Request. Again the same way you did with MessageBody.

Appellative answered 16/12, 2019 at 9:45 Comment(1)
Body template will be. Action=SendMessage&MessageGroupId=$input.params('MessageGroupId')&MessageDeduplicationId=$input.params('MessageDeduplicationId')&MessageBody=$input.bodyConcuss
C
5

You can extract the MessageGroupId and MessageDeduplicationId from the response of API gateway. eg: if the payload is something like below, you can extract the any properties from the payload. Clear video tutorial here. https://www.youtube.com/watch?v=dXa9KA-G9Dg

Assume the payload is like this:

{
  "data" :{
    "jobNumber": "123456"
  }
}

Then the template in api gateway is below. It extract the jobNumber from the payload and set to MessageGroupId. Here the MessageDeduplicationId is getting from the context.

#set($dedupId = $context.requestId)
#set($groupId = $input.json('$.data.jobNumber'))
Action=SendMessage&MessageBody=$input.body&MessageGroupId=$groupId&MessageDeduplicationId=$dedupId

Coats answered 15/10, 2022 at 4:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.