diff --git a/packages/sns/lib/sns/AbstractSnsService.ts b/packages/sns/lib/sns/AbstractSnsService.ts index e6b0d08b..315bd533 100644 --- a/packages/sns/lib/sns/AbstractSnsService.ts +++ b/packages/sns/lib/sns/AbstractSnsService.ts @@ -10,7 +10,9 @@ import type { SNS_MESSAGE_BODY_TYPE } from '../types/MessageTypes.ts' import { deleteSns, initSns } from '../utils/snsInitter.ts' // https://docs.aws.amazon.com/general/latest/gr/sns.html -export const SNS_MESSAGE_MAX_SIZE = 256 * 1024 // 256KB +export const SNS_MESSAGE_HARD_LIMIT = 256 * 1024 // 256KB - AWS SNS total message size limit (body + attributes) +export const SNS_MESSAGE_ATTRIBUTE_BUFFER = 30 * 1024 // 30KB - reserved space for message attributes and overhead +export const SNS_MESSAGE_MAX_SIZE = SNS_MESSAGE_HARD_LIMIT - SNS_MESSAGE_ATTRIBUTE_BUFFER // 226KB - maximum allowed message body size export type SNSDependencies = QueueDependencies & { snsClient: SNSClient diff --git a/packages/sns/lib/utils/snsUtils.ts b/packages/sns/lib/utils/snsUtils.ts index 7f541e38..8ad35028 100644 --- a/packages/sns/lib/utils/snsUtils.ts +++ b/packages/sns/lib/utils/snsUtils.ts @@ -187,8 +187,8 @@ export async function findSubscriptionByTopicAndQueue( * Calculates the size of an outgoing SNS message. * * SNS imposes a 256 KB limit on the total size of a message, which includes both the message body and any metadata (attributes). - * This function currently computes the size based solely on the message body, as no attributes are included at this time. - * For future updates, if message attributes are added, their sizes should also be considered. + * This function computes the size based solely on the message body. The reserved buffer for message attributes and overhead + * is accounted for in SNS_MESSAGE_ATTRIBUTE_BUFFER, which is subtracted from SNS_MESSAGE_HARD_LIMIT to derive SNS_MESSAGE_MAX_SIZE. * * Reference: https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html * diff --git a/packages/sqs/lib/sqs/AbstractSqsService.ts b/packages/sqs/lib/sqs/AbstractSqsService.ts index bb06e59d..54bb59ad 100644 --- a/packages/sqs/lib/sqs/AbstractSqsService.ts +++ b/packages/sqs/lib/sqs/AbstractSqsService.ts @@ -9,7 +9,9 @@ import type { SQSMessage } from '../types/MessageTypes.ts' import { deleteSqs, initSqs } from '../utils/sqsInitter.ts' // https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-messages.html -export const SQS_MESSAGE_MAX_SIZE = 1024 * 1024 // 1 MiB +export const SQS_MESSAGE_HARD_LIMIT = 1024 * 1024 // 1 MiB - AWS SQS total message size limit (body + attributes) +export const SQS_MESSAGE_ATTRIBUTE_BUFFER = 30 * 1024 // 30KB - reserved space for message attributes and overhead +export const SQS_MESSAGE_MAX_SIZE = SQS_MESSAGE_HARD_LIMIT - SQS_MESSAGE_ATTRIBUTE_BUFFER // 994KB - maximum allowed message body size export const SQS_RESOURCE_ANY = Symbol('any') export const SQS_RESOURCE_CURRENT_QUEUE = Symbol('current_queue') diff --git a/packages/sqs/lib/utils/sqsUtils.ts b/packages/sqs/lib/utils/sqsUtils.ts index 3d4ecdaa..83186ae7 100644 --- a/packages/sqs/lib/utils/sqsUtils.ts +++ b/packages/sqs/lib/utils/sqsUtils.ts @@ -275,8 +275,8 @@ export async function deleteQueue( * Calculates the size of an outgoing SQS message. * * SQS imposes a 1 MiB limit on the total size of a message, which includes both the message body and any metadata (attributes). - * This function currently computes the size based solely on the message body, as no attributes are included at this time. - * For future updates, if message attributes are added, their sizes should also be considered. + * This function computes the size based solely on the message body. The reserved buffer for message attributes and overhead + * is accounted for in SQS_MESSAGE_ATTRIBUTE_BUFFER, which is subtracted from SQS_MESSAGE_HARD_LIMIT to derive SQS_MESSAGE_MAX_SIZE. * * Reference: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes */