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

(aws-events-targets): Using an imported DLQ with an event rule target throws Error: Cannot assign Dead Letter Queue in region ${Token[TOKEN.35]} to the rule XYZEventRule89558AAC in region eu-west-1. Both the queue and the rule must be in the same region. #28165

Closed
JeromeGuyon opened this issue Nov 28, 2023 · 10 comments · Fixed by #28285
Labels
@aws-cdk/aws-events-targets bug This issue is a bug. effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0

Comments

@JeromeGuyon
Copy link
Contributor

JeromeGuyon commented Nov 28, 2023

Please add your +1 👍 to let us know you have encountered this

Status: RESOLVED

Overview:

All users of aws-events-targets who created a Rule with the SqsQueue target and passed an imported queue to the deadLetterQueue prop would receive an error similar to:

Complete Error Message:

Error: Cannot assign Dead Letter Queue in region ${Token[TOKEN.35]} to the rule XYZEventRule89558AAC in region eu-west-1. Both the queue and the rule must be in the same region.

Workaround:

Solution:

Upgrade to 2.116.0 or higher.

Related Issues:


Original report

Describe the bug

Previously (2.95.1), I was able to associate a DLQ to a Rule.

In last version (2.111.0), it is nor more possible :

const failedEventQueue = sqs.Queue.fromQueueArn(
      this,
      "FailedEventsQueue",
      ssm.StringParameter.valueForStringParameter(
        this,
        `xyz/failed-events-queue-arn`
      )
    );
    
eventRule.addTarget(
      new targets.SqsQueue(aQueue, {
        messageGroupId: messageGroupId,
        deadLetterQueue: failedEventQueue,
        maxEventAge: cdk.Duration.seconds(60),
        retryAttempts: 0,
      })
    ); 

Generate

Error: Cannot assign Dead Letter Queue in region ${Token[TOKEN.35]} to the rule XYZEventRule89558AAC in region eu-west-1. Both the queue and the rule must be in the same region.

Expected Behavior

It should be possible to support imported SQS Queue as DLQ.

Current Behavior

Error: Cannot assign Dead Letter Queue in region ${Token[TOKEN.35]} to the rule XYZEventRule89558AAC in region eu-west-1. Both the queue and the rule must be in the same region.

Reproduction Steps

const failedEventQueue = sqs.Queue.fromQueueArn(
      this,
      "FailedEventsQueue",
      ssm.StringParameter.valueForStringParameter(
        this,
        `xyz/failed-events-queue-arn`
      )
    );
    
eventRule.addTarget(
      new targets.SqsQueue(aQueue, {
        messageGroupId: messageGroupId,
        deadLetterQueue: failedEventQueue,
        maxEventAge: cdk.Duration.seconds(60),
        retryAttempts: 0,
      })
    ); 

and in stack
env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

Possible Solution

N/A

Additional Information/Context

No response

CDK CLI Version

2.108.0

Framework Version

No response

Node.js Version

v18.13.0

OS

macos

Language

TypeScript

Language Version

TypeScript (5.2.2)

Other information

No response

@JeromeGuyon JeromeGuyon added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 28, 2023
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 28, 2023
@pahud
Copy link
Contributor

pahud commented Nov 28, 2023

Is the error message from cloudformation?

Looks like the region of the failedEventQueue can't be resolved.

const failedEventQueue = sqs.Queue.fromQueueArn(
      this,
      "FailedEventsQueue",
      ssm.StringParameter.valueForStringParameter(
        this,
        `xyz/failed-events-queue-arn`
      )
    );

Can you assign a static ARN to failedEventQueue without retrieving from ssm and see if the error still exists?

And, can you confirm if the value is successfully retrieved from the given parameter?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 28, 2023
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Nov 30, 2023
@sjbthfc2
Copy link

sjbthfc2 commented Dec 5, 2023

I am having the same issue, I have checked that the Rule and Dead Letter Queue are in the same region but I can't resolve this.

@sjbthfc2
Copy link

sjbthfc2 commented Dec 5, 2023

I can confirm that after reverting back to CDK version 2.93.0, it works. Looks like this is a bug with latest version.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Dec 5, 2023
@KentarouTakeda
Copy link

I also encountered the same problem. The region settings are fine and they are set in stackProps.env.

Node.js: v20.9.0
TypeScript: 5.3.3
CDK: 2.114.1

@JeromeGuyon
Copy link
Contributor Author

Is the error message from cloudformation?

Looks like the region of the failedEventQueue can't be resolved.

const failedEventQueue = sqs.Queue.fromQueueArn(
      this,
      "FailedEventsQueue",
      ssm.StringParameter.valueForStringParameter(
        this,
        `xyz/failed-events-queue-arn`
      )
    );

Can you assign a static ARN to failedEventQueue without retrieving from ssm and see if the error still exists?

And, can you confirm if the value is successfully retrieved from the given parameter?

Sorry for the delay, :

I tried with const deadLetterQueue = new sqs.Queue( => Working
With const deadLetterQueue = sqs.Queue.fromQueueArn(this,'MyDeadLetterQueue',"arn:aws:sqs:eu-west-1:444455556666:queue1") => Synth fails

issue still exists in 2.114.1

@JeromeGuyon
Copy link
Contributor Author

JeromeGuyon commented Dec 7, 2023

last working release : 2.108.1, bug introduced in 2.109.0

Maybe it has been introduced with this PR
633dbe2
#27906

@JeromeGuyon
Copy link
Contributor Author

With #27906 PR, the region/account is now considered as resolved and are not anymore tokens.

As a workaround, I suggest changing

return [TokenComparison.SAME, TokenComparison.BOTH_UNRESOLVED].includes(Token.compareStrings(dim1, dim2));

to

return [TokenComparison.SAME, TokenComparison.BOTH_UNRESOLVED,, TokenComparison.ONE_UNRESOLVED].includes(Token.compareStrings(dim1, dim2));

@kaizencc
Copy link
Contributor

Looks like a [small] regression we've introduced, so labeling this p0. It isn't going to matter much in terms of priority, as @JeromeGuyon has already created a fix that has been accepted (thanks :)).

@mergify mergify bot closed this as completed in #28285 Dec 21, 2023
mergify bot pushed a commit that referenced this issue Dec 21, 2023
…28165) (#28285)

This PR fixes the bug where imported SQS queue cannot be used as Rule DeadLetterQueue, since fromQueueArn can resolve region and account from v2.109.0

Closes #28165

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@comcalvi comcalvi changed the title (aws-events-targets): (imported dead letter queue could not anymore be associated to a Rule) (aws-events-targets): Using an imported DLQ with an event rule target throws Error: Cannot assign Dead Letter Queue in region Dec 22, 2023
@comcalvi comcalvi changed the title (aws-events-targets): Using an imported DLQ with an event rule target throws Error: Cannot assign Dead Letter Queue in region (aws-events-targets): Using an imported DLQ with an event rule target throws Error: Cannot assign Dead Letter Queue in region...Both the queue and the rule must be in the same region. Dec 22, 2023
@comcalvi comcalvi changed the title (aws-events-targets): Using an imported DLQ with an event rule target throws Error: Cannot assign Dead Letter Queue in region...Both the queue and the rule must be in the same region. (aws-events-targets): Using an imported DLQ with an event rule target throws Error: Cannot assign Dead Letter Queue in region ${Token[TOKEN.35]} to the rule XYZEventRule89558AAC in region eu-west-1. Both the queue and the rule must be in the same region. Dec 22, 2023
@comcalvi comcalvi added the management/tracking Issues that track a subject or multiple issues label Dec 22, 2023
@comcalvi comcalvi pinned this issue Dec 22, 2023
mergify bot pushed a commit to cdklabs/aws-cdk-notices that referenced this issue Dec 22, 2023
paulhcsun pushed a commit to paulhcsun/aws-cdk that referenced this issue Jan 5, 2024
…ws#28165) (aws#28285)

This PR fixes the bug where imported SQS queue cannot be used as Rule DeadLetterQueue, since fromQueueArn can resolve region and account from v2.109.0

Closes aws#28165

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@MrArnoldPalmer MrArnoldPalmer unpinned this issue Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events-targets bug This issue is a bug. effort/medium Medium work item – several days of effort management/tracking Issues that track a subject or multiple issues p0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants