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

(integ-test): multiple AwsApiCalls with the same action creates duplicate names #25014

Closed
joel-aws opened this issue Apr 10, 2023 · 1 comment · Fixed by #25241
Closed

(integ-test): multiple AwsApiCalls with the same action creates duplicate names #25014

joel-aws opened this issue Apr 10, 2023 · 1 comment · Fixed by #25241
Labels

Comments

@joel-aws
Copy link
Contributor

joel-aws commented Apr 10, 2023

Describe the bug

If you have > 1 awsApiCall calls on the same API & Action, then there will be a collision in the constructs' names.

Expected Behavior

Sometimes you have to do the same API call against different resources, so I would expect different construct names.

Current Behavior

Any AwsApiCall with the same API + action instantiates constructs with the same name.

Reproduction Steps

import { AccountRootPrincipal, Role } from 'aws-cdk-lib/aws-iam';
import { Key } from 'aws-cdk-lib/aws-kms';
import { App, CfnOutput, RemovalPolicy, Stack } from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import { DeduplicationScope, FifoThroughputLimit, Queue, QueueEncryption } from 'aws-cdk-lib/aws-sqs';

const app = new App();

const stack = new Stack(app, 'aws-cdk-sqs');

const dlq = new Queue(stack, 'DeadLetterQueue');
const queue = new Queue(stack, 'Queue', {
  deadLetterQueue: { queue: dlq, maxReceiveCount: 5 },
});
const fifo = new Queue(stack, 'FifoQueue', {
  fifo: true,
  encryptionMasterKey: new Key(stack, 'EncryptionKey', { removalPolicy: RemovalPolicy.DESTROY }),
});
const highThroughputFifo = new Queue(stack, 'HighThroughputFifoQueue', {
  fifo: true,
  fifoThroughputLimit: FifoThroughputLimit.PER_MESSAGE_GROUP_ID,
  deduplicationScope: DeduplicationScope.MESSAGE_GROUP,
});
const kmsManagedEncryptedQueue = new Queue(stack, 'kmsManagedEncryptedQueue', {
  encryption: QueueEncryption.KMS_MANAGED,
});
const unencryptedQueue = new Queue(stack, 'UnencryptedQueue', {
  encryption: QueueEncryption.UNENCRYPTED,
});
const ssl = new Queue(stack, 'SSLQueue', { enforceSSL: true });

const role = new Role(stack, 'Role', {
  assumedBy: new AccountRootPrincipal(),
});

dlq.grantConsumeMessages(role);
queue.grantConsumeMessages(role);
fifo.grantConsumeMessages(role);
highThroughputFifo.grantConsumeMessages(role);
kmsManagedEncryptedQueue.grantConsumeMessages(role);
unencryptedQueue.grantConsumeMessages(role);
ssl.grantConsumeMessages(role);

new CfnOutput(stack, 'QueueUrl', { value: queue.queueUrl });

const integtest = new integ.IntegTest(app, 'SqsTest', {
  testCases: [stack],
});

// GIVEN a defaults-only SQS Queue
// WHEN we query it for the `sqsManagedSseEnabled` attribute
const defaultQueueAttrs = integtest.assertions.awsApiCall('SQS', 'getQueueAttributes', {
  QueueUrl: queue.queueUrl,
  AttributeNames: ['SqsManagedSseEnabled'],
});
// THEN we expect it to return `true`
defaultQueueAttrs.expect(integ.ExpectedResult.stringLikeRegexp('true'));


// GIVEN a SQS Queue with KMS
// WHEN we query it for the `sqsManagedSseEnabled` attribute
const kmsQueueAttrs = integtest.assertions.awsApiCall('SQS', 'getQueueAttributes', {
  QueueUrl: kmsManagedEncryptedQueue.queueUrl,
  AttributeNames: ['SqsManagedSseEnabled'],
});
// THEN we expect it to return `false`
kmsQueueAttrs.expect(integ.ExpectedResult.stringLikeRegexp('false'));

app.synth();

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.70.0

Framework Version

No response

Node.js Version

16.3.0

OS

Mac

Language

Typescript

Language Version

No response

Other information

No response

@joel-aws joel-aws added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2023
@indrora indrora added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2023
@mergify mergify bot closed this as completed in #25241 Apr 28, 2023
mergify bot pushed a commit that referenced this issue Apr 28, 2023
… different parameters (#25241)

This PR allows multiple AwsApiCalls with the same action and different parameters.
Closes #25014

To be able to test the new behavior, a new integration test has been added in aws-redshift-alpha package.

Next possible step (to be discussed): add an optional `callNumber` in `awsApiCall` method to be able to use this method twice with the same action and same parameters.
@github-actions
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants