Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-sqs/lib/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export interface QueueProps {
/**
* The limit of how many bytes that a message can contain before Amazon SQS rejects it.
*
* You can specify an integer value from 1024 bytes (1 KiB) to 262144 bytes
* (256 KiB). The default value is 262144 (256 KiB).
* You can specify an integer value from 1024 bytes (1 KiB) to 1048576 bytes
* (1 MiB). The default value is 262144 (256 KiB).
*
* @default 256KiB
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-sqs/lib/validate-queue-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const queueValidationRules: ValidationRule<QueueProps>[] = [
message: (props) => `delivery delay must be between 0 and 900 seconds, but ${props.deliveryDelay?.toSeconds()} was provided`,
},
{
condition: (props) => validateRange(props.maxMessageSizeBytes, 1_024, 262_144),
message: (props) => `maximum message size must be between 1,024 and 262,144 bytes, but ${props.maxMessageSizeBytes} was provided`,
condition: (props) => validateRange(props.maxMessageSizeBytes, 1_024, 1_048_576),
message: (props) => `maximum message size must be between 1,024 and 1,048,576 bytes, but ${props.maxMessageSizeBytes} was provided`,
},
{
condition: (props) => validateRange(props.retentionPeriod?.toSeconds(), 60, 1_209_600),
Expand Down
56 changes: 56 additions & 0 deletions packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,62 @@ test('message retention period can be provided as a parameter', () => {
});
});

test('maxMessageSizeBytes validation enforces correct limits', () => {
const stack = new Stack();

// Test minimum boundary - should fail
expect(() => new sqs.Queue(stack, 'TooSmall', {
maxMessageSizeBytes: 1023,
})).toThrow('Queue initialization failed due to the following validation error(s):\n- maximum message size must be between 1,024 and 1,048,576 bytes, but 1023 was provided');

// Test maximum boundary - should fail
expect(() => new sqs.Queue(stack, 'TooLarge', {
maxMessageSizeBytes: 1048577,
})).toThrow('Queue initialization failed due to the following validation error(s):\n- maximum message size must be between 1,024 and 1,048,576 bytes, but 1048577 was provided');

// Test valid minimum boundary - should succeed
expect(() => new sqs.Queue(stack, 'MinValid', {
maxMessageSizeBytes: 1024,
})).not.toThrow();

// Test valid maximum boundary - should succeed
expect(() => new sqs.Queue(stack, 'MaxValid', {
maxMessageSizeBytes: 1048576,
})).not.toThrow();
});

test('maxMessageSizeBytes works with CDK tokens', () => {
const stack = new Stack();
const parameter = new CfnParameter(stack, 'MessageSize', { type: 'Number' });

// Should not throw for tokens (validation skipped)
expect(() => new sqs.Queue(stack, 'TokenQueue', {
maxMessageSizeBytes: parameter.valueAsNumber,
})).not.toThrow();
});

test('multiple validation errors include maxMessageSizeBytes', () => {
const stack = new Stack();

expect(() => new sqs.Queue(stack, 'MultiError', {
maxMessageSizeBytes: 2000000,
retentionPeriod: Duration.seconds(30),
})).toThrow(/maximum message size must be between 1,024 and 1,048,576 bytes.*message retention period must be between 60 and 1,209,600 seconds/s);
});

test('maxMessageSizeBytes synthesizes correct CloudFormation', () => {
const stack = new Stack();

new sqs.Queue(stack, 'LargeMessageQueue', {
maxMessageSizeBytes: 1048576,
});

const template = Template.fromStack(stack);
template.hasResourceProperties('AWS::SQS::Queue', {
MaximumMessageSize: 1048576,
});
});

test('addToPolicy will automatically create a policy for this queue', () => {
const stack = new Stack();
const queue = new sqs.Queue(stack, 'MyQueue');
Expand Down
Loading