Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events-targets): imported sqs queue cannot be used as a rule dlq (#28165) #28285

Merged
merged 9 commits into from
Dec 21, 2023
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-events-targets/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ export function addToDeadLetterQueueResourcePolicy(rule: events.IRule, queue: sq
* @internal
*/
function sameEnvDimension(dim1: string, dim2: string) {
return [TokenComparison.SAME, TokenComparison.BOTH_UNRESOLVED].includes(Token.compareStrings(dim1, dim2));
return [TokenComparison.SAME, TokenComparison.ONE_UNRESOLVED, TokenComparison.BOTH_UNRESOLVED].includes(Token.compareStrings(dim1, dim2));
}
38 changes: 37 additions & 1 deletion packages/aws-cdk-lib/aws-events-targets/test/sqs/sqs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Match, Template } from '../../../assertions';
import * as events from '../../../aws-events';
import * as kms from '../../../aws-kms';
import * as sqs from '../../../aws-sqs';
import { App, Duration, Stack } from '../../../core';
import * as ssm from '../../../aws-ssm';
import { App, CustomResource, Duration, Stack } from '../../../core';
import * as cxapi from '../../../cx-api';
import * as targets from '../../lib';

Expand Down Expand Up @@ -401,3 +402,38 @@ test('specifying retry policy with 0 retryAttempts', () => {
],
});
});

test('dead letter queue is imported', () => {
const stack = new Stack();
const queue = new sqs.Queue(stack, 'MyQueue', { fifo: true });
const rule = new events.Rule(stack, 'MyRule', {
schedule: events.Schedule.rate(Duration.hours(1)),
});

const dlqArn = 'arn:aws:sqs:eu-west-1:444455556666:queue1';
const deadLetterQueue = sqs.Queue.fromQueueArn(stack, 'MyDeadLetterQueue', dlqArn);

// WHEN
rule.addTarget(new targets.SqsQueue(queue, {
deadLetterQueue,
}));

Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
ScheduleExpression: 'rate(1 hour)',
State: 'ENABLED',
Targets: [
{
Arn: {
'Fn::GetAtt': [
'MyQueueE6CA6235',
'Arn',
],
},
Id: 'Target0',
DeadLetterConfig: {
Arn: dlqArn
},
},
],
})
});
Loading