Hello, I have created a queue and attached to lam...
# help
u
Hello, I have created a queue and attached to lambda function but somehow the consumer lambda is invoking twice though I was manually deleting the message after processing. Could any one help me with this?
@Frank
f
Hey @Uday Bhaskar Gajavalli is it happening on
sst start
or after
sst deploy
?
u
it's in sst start
We have multiple queues and their respective consumer functions. Still facing the same issue
f
If you look in ur terminal, u see the consumer invoked twice?
Do both invocations have the same or different request id?
u
It has different request ids
f
I see. How long is it between the two requests?
u
Less than a second or 2 seconds
f
could it be that the same message was sent twice to the queue?
u
Queue is only getting 1 message but somehow the consumer is invoking twice and also I have written logic for deleting message from queue after processing in the consumer functions
though the the consumer is invoking second time
f
hmm u shouldn’t have to delete manually, that’s done automatically
Can i see how u r creating the queue?
u
Copy code
const clickQueue = new sst.Queue(this, "clickQueue", {
      consumer: {
        handler:
          "path",
        timeout: 10,
      },
      sqsQueue: {
        visibilityTimeout: Duration.seconds(30),
      },
    });
f
that looks right to me..
one thing I’d check is if u look at the xray trace for one of the consumer invocation, can you share what u see there?
u
Let me check there too
f
Yeah, I wonder if the request has failed and Lambda is doing a retry
u
import { SQSEvent } from _"aws-lambda"_;
export async function clickQueueConsumer(
_event_: SQSEvent) {
const failedMessageIds = []; for (const record of event.Records) { try { console.log(
_"clickQueueConsumer: "_, record.body);
} catch (e) { failedMessageIds.push(record.messageId); } } return { batchItemFailures: failedMessageIds.map((
_id_) => {
return { itemIdentifier: id, }; }), }; }
f
Can you try commenting out everything, just an empty function, see if it gets call twice.
Copy code
export async function clickQueueConsumer() {
 console.log("called");
}
u
Yeah it's getting called twice
f
hmm.. that’s really weird
Yeah if u can look up xray, that should tell us if SQS is calling the consumer twice or if it’s a Lambda retry
u
Unfortunately, I don't have access to view X-Ray
I found this from the Log groups of the clickQueueConsumer function receiveMessage() - stop keep alive timer Timeout { _idleTimeout: 540000, _idlePrev: [TimersList], _idleNext: [TimersList], _idleStart: 494, _onTimeout: [Function (anonymous)], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: true, [Symbol(kHasPrimitive)]: false, [Symbol(asyncId)]: 19, [Symbol(triggerId)]: 5 }
f
Can u share the entire log of a request?
u
START RequestId: fcc73f27-8219-5ad9-ac7c-65e815b62d58 Version: $LATEST 2022-04-12T150640.065Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO connectAndSendMessage() 2022-04-12T150640.142Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO ws.onopen 2022-04-12T150640.142Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO sendMessage() - send request 2022-04-12T150640.144Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO sendMessage() - sending request via WebSocket 2022-04-12T150640.145Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO sendMessage() - start keep alive timer 2022-04-12T150645.371Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO ws.onmessage { "action": "client.lambdaResponse", "debugRequestId": "fcc73f27-8219-5ad9-ac7c-65e815b62d58-1649776000065", "stubConnectionId": "QeRMDfhtoAMCLww=", "payload": "H4sIAAAAAAAACqtWKkotLsjPK051SSxJVLLKK83JqQUACtSALhUAAAA=" } 2022-04-12T150645.371Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO receiveMessage() 2022-04-12T150645.371Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO receiveMessage() - received payload 2022-04-12T150645.374Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO receiveMessage() - stop keep alive timer Timeout { _idleTimeout: 540000, _idlePrev: [TimersList], _idleNext: [TimersList], _idleStart: 494, _onTimeout: [Function (anonymous)], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: true, [Symbol(kHasPrimitive)]: false, [Symbol(asyncId)]: 19, [Symbol(triggerId)]: 5 } END RequestId: fcc73f27-8219-5ad9-ac7c-65e815b62d58 REPORT RequestId: fcc73f27-8219-5ad9-ac7c-65e815b62d58 Duration: 5312.22 ms Billed Duration: 5313 ms Memory Size: 1024 MB Max Memory Used: 81 MB Init Duration: 472.61 ms XRAY TraceId: 1-6255957f-612a77240c203fd10acb1f44 SegmentId: 61e68ede2e99e67d Sampled: true
f
it looks fine
And there’s another request right after this with the same
event
?
u
Is it normal?
sendMessage()
in consumerfunction log
Yeah the same event but with different requestId
f
yeah, it’s a stub Lambda, and it’s sending a websocket message to ur local with the request info.
u
Ohh Okay.
f
Does this happen to all queues in ur app?
u
Yes. for every queue
f
hmm.. a couple of things I’d try: • set Lambda retry to 0 (disable retry) => this tells us if the 2nd request is a retry • removing the Lambda consumer, and after u call sendMessage, go to AWS SQS console and inspect the queue => this tells us if the same message is sent twice • create a new SST app with just a queue and see if the same issue can be reproduced. You can use this sample repo.
u
Can we set the lambda retry to 0 from SST or should I do it from AWS Console?
I have removed the consumer and somehow same message is sent twice into the queue
j
Are you still having this issue @Uday Bhaskar Gajavalli?