Skip to content

Commit

Permalink
Fix #134 0.76.0: SNS -> publish to subscribed SQS queue, "Records" as…
Browse files Browse the repository at this point in the history
…sumption leads to lost message, empty array. #134

There is no need to check `    if (sub["Attributes"]["RawMessageDelivery"] === "true") ` inside `publishSqs`, this `RawMessageDelivery` check-process is already handled by `publish`.
The `event` object is what should be sent directly to an sqs endpoint.

This also works with serverless-offline-sqs plugin.
  • Loading branch information
jimmy-shaojun committed Feb 25, 2023
1 parent 5eb5031 commit a11eea8
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/sns-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,29 +299,14 @@ export class SNSServer implements ISNSServer {
const sqsEndpoint = `${subEndpointUrl.protocol}//${subEndpointUrl.host}/`;
const sqs = new SQS({ endpoint: sqsEndpoint, region: this.region });

if (sub["Attributes"]["RawMessageDelivery"] === "true") {
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: event,
MessageAttributes: formatMessageAttributes(messageAttributes),
...(messageGroupId && { MessageGroupId: messageGroupId }),
})
.promise();
} else {
const records = JSON.parse(event).Records ?? [];
const messagePromises = records.map((record) => {
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: JSON.stringify(record.Sns),
MessageAttributes: formatMessageAttributes(messageAttributes),
...(messageGroupId && { MessageGroupId: messageGroupId }),
})
.promise();
});
return Promise.all(messagePromises);
}
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: event,
MessageAttributes: formatMessageAttributes(messageAttributes),
...(messageGroupId && { MessageGroupId: messageGroupId }),
})
.promise();
}

public publish(
Expand Down

0 comments on commit a11eea8

Please sign in to comment.