Skip to content

Commit 87b1614

Browse files
authored
chore: Include buffers (30MB) for SNS and SQS message payloads (#408)
* chore: Decrease SNS message max size threshold * chore: Add buffers for SNS and SQS messages
1 parent 09b2c12 commit 87b1614

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

packages/sns/lib/sns/AbstractSnsService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import type { SNS_MESSAGE_BODY_TYPE } from '../types/MessageTypes.ts'
1010
import { deleteSns, initSns } from '../utils/snsInitter.ts'
1111

1212
// https://docs.aws.amazon.com/general/latest/gr/sns.html
13-
export const SNS_MESSAGE_MAX_SIZE = 256 * 1024 // 256KB
13+
export const SNS_MESSAGE_HARD_LIMIT = 256 * 1024 // 256KB - AWS SNS total message size limit (body + attributes)
14+
export const SNS_MESSAGE_ATTRIBUTE_BUFFER = 30 * 1024 // 30KB - reserved space for message attributes and overhead
15+
export const SNS_MESSAGE_MAX_SIZE = SNS_MESSAGE_HARD_LIMIT - SNS_MESSAGE_ATTRIBUTE_BUFFER // 226KB - maximum allowed message body size
1416

1517
export type SNSDependencies = QueueDependencies & {
1618
snsClient: SNSClient

packages/sns/lib/utils/snsUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ export async function findSubscriptionByTopicAndQueue(
187187
* Calculates the size of an outgoing SNS message.
188188
*
189189
* SNS imposes a 256 KB limit on the total size of a message, which includes both the message body and any metadata (attributes).
190-
* This function currently computes the size based solely on the message body, as no attributes are included at this time.
191-
* For future updates, if message attributes are added, their sizes should also be considered.
190+
* This function computes the size based solely on the message body. The reserved buffer for message attributes and overhead
191+
* is accounted for in SNS_MESSAGE_ATTRIBUTE_BUFFER, which is subtracted from SNS_MESSAGE_HARD_LIMIT to derive SNS_MESSAGE_MAX_SIZE.
192192
*
193193
* Reference: https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html
194194
*

packages/sqs/lib/sqs/AbstractSqsService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import type { SQSMessage } from '../types/MessageTypes.ts'
99
import { deleteSqs, initSqs } from '../utils/sqsInitter.ts'
1010

1111
// https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html
12-
export const SQS_MESSAGE_MAX_SIZE = 1024 * 1024 // 1 MiB
12+
export const SQS_MESSAGE_HARD_LIMIT = 1024 * 1024 // 1 MiB - AWS SQS total message size limit (body + attributes)
13+
export const SQS_MESSAGE_ATTRIBUTE_BUFFER = 30 * 1024 // 30KB - reserved space for message attributes and overhead
14+
export const SQS_MESSAGE_MAX_SIZE = SQS_MESSAGE_HARD_LIMIT - SQS_MESSAGE_ATTRIBUTE_BUFFER // 994KB - maximum allowed message body size
1315
export const SQS_RESOURCE_ANY = Symbol('any')
1416
export const SQS_RESOURCE_CURRENT_QUEUE = Symbol('current_queue')
1517

packages/sqs/lib/utils/sqsUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ export async function deleteQueue(
275275
* Calculates the size of an outgoing SQS message.
276276
*
277277
* SQS imposes a 1 MiB limit on the total size of a message, which includes both the message body and any metadata (attributes).
278-
* This function currently computes the size based solely on the message body, as no attributes are included at this time.
279-
* For future updates, if message attributes are added, their sizes should also be considered.
278+
* This function computes the size based solely on the message body. The reserved buffer for message attributes and overhead
279+
* is accounted for in SQS_MESSAGE_ATTRIBUTE_BUFFER, which is subtracted from SQS_MESSAGE_HARD_LIMIT to derive SQS_MESSAGE_MAX_SIZE.
280280
*
281281
* Reference: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes
282282
*/

0 commit comments

Comments
 (0)