From 6235428c871a0fd044bf41c6a07e577e5ce973cd Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:49:25 +0900 Subject: [PATCH 1/2] fix(sqs): imported queue ignores environment from arn --- packages/aws-cdk-lib/aws-sqs/lib/queue.ts | 4 ++- packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-sqs/lib/queue.ts b/packages/aws-cdk-lib/aws-sqs/lib/queue.ts index 16fb120d8f100..a122045571937 100644 --- a/packages/aws-cdk-lib/aws-sqs/lib/queue.ts +++ b/packages/aws-cdk-lib/aws-sqs/lib/queue.ts @@ -282,7 +282,9 @@ export class Queue extends QueueBase { } } - return new Import(scope, id); + return new Import(scope, id, { + environmentFromArn: attrs.queueArn, + }); } /** diff --git a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts index 9ec5da716e28d..5d87be2020ff9 100644 --- a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts +++ b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts @@ -284,6 +284,38 @@ describe('export and import', () => { }); expect(stack.resolve(imports.queueName)).toEqual('queue1'); }); + + test('sets account for imported queue env by fromQueueAttributes', () => { + const stack = new Stack(); + const imported = sqs.Queue.fromQueueAttributes(stack, 'Imported', { + queueArn: 'arn:aws:sns:us-west-2:999999999999:queue', + }); + + expect(imported.env.account).toEqual('999999999999'); + }); + + test('sets region for imported queue env by fromQueueAttributes', () => { + const stack = new Stack(); + const imported = sqs.Queue.fromQueueAttributes(stack, 'Imported', { + queueArn: 'arn:aws:sns:us-west-2:999999999999:queue', + }); + + expect(imported.env.region).toEqual('us-west-2'); + }); + + test('sets account for imported queue env by fromQueueArn', () => { + const stack = new Stack(); + const imported = sqs.Queue.fromQueueArn(stack, 'Imported', 'arn:aws:sns:us-west-2:999999999999:queue'); + + expect(imported.env.account).toEqual('999999999999'); + }); + + test('sets region for imported queue env by fromQueueArn', () => { + const stack = new Stack(); + const imported = sqs.Queue.fromQueueArn(stack, 'Imported', 'arn:aws:sns:us-west-2:123456789012:queue'); + + expect(imported.env.region).toEqual('us-west-2'); + }); }); describe('grants', () => { From dd8158c438e0f3fc5b87774fd43344e4f45ae7ea Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:13:12 +0900 Subject: [PATCH 2/2] fix unit tests --- packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts index 5d87be2020ff9..0c0492b26f28b 100644 --- a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts +++ b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts @@ -288,7 +288,7 @@ describe('export and import', () => { test('sets account for imported queue env by fromQueueAttributes', () => { const stack = new Stack(); const imported = sqs.Queue.fromQueueAttributes(stack, 'Imported', { - queueArn: 'arn:aws:sns:us-west-2:999999999999:queue', + queueArn: 'arn:aws:sqs:us-west-2:999999999999:queue', }); expect(imported.env.account).toEqual('999999999999'); @@ -297,7 +297,7 @@ describe('export and import', () => { test('sets region for imported queue env by fromQueueAttributes', () => { const stack = new Stack(); const imported = sqs.Queue.fromQueueAttributes(stack, 'Imported', { - queueArn: 'arn:aws:sns:us-west-2:999999999999:queue', + queueArn: 'arn:aws:sqs:us-west-2:999999999999:queue', }); expect(imported.env.region).toEqual('us-west-2'); @@ -305,14 +305,14 @@ describe('export and import', () => { test('sets account for imported queue env by fromQueueArn', () => { const stack = new Stack(); - const imported = sqs.Queue.fromQueueArn(stack, 'Imported', 'arn:aws:sns:us-west-2:999999999999:queue'); + const imported = sqs.Queue.fromQueueArn(stack, 'Imported', 'arn:aws:sqs:us-west-2:999999999999:queue'); expect(imported.env.account).toEqual('999999999999'); }); test('sets region for imported queue env by fromQueueArn', () => { const stack = new Stack(); - const imported = sqs.Queue.fromQueueArn(stack, 'Imported', 'arn:aws:sns:us-west-2:123456789012:queue'); + const imported = sqs.Queue.fromQueueArn(stack, 'Imported', 'arn:aws:sqs:us-west-2:123456789012:queue'); expect(imported.env.region).toEqual('us-west-2'); });