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

apigateway: unique name for restApiName #32564

Open
1 of 2 tasks
kmkhr opened this issue Dec 18, 2024 · 2 comments
Open
1 of 2 tasks

apigateway: unique name for restApiName #32564

kmkhr opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway closing-soon This issue will automatically close in 4 days unless further comments are made. feature-request A feature should be added or improved. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@kmkhr
Copy link

kmkhr commented Dec 18, 2024

Describe the feature

Currently the resource ID is set in restApiName, but change it to a CloudFormation-compatible unique identifier such as Names.uniqueResourceName.

Use Case

Easily identification of APIs on the management console.

Proposed Solution

https://github.com/aws/aws-cdk/blob/v2.173.2/packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts#L374

diff --git a/packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts b/packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts
index 32dca38262..91019e8340 100644
--- a/packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts
+++ b/packages/aws-cdk-lib/aws-apigateway/lib/restapi.ts
@@ -372,11 +372,14 @@ export abstract class RestApiBase extends Resource implements IRestApi {
   protected cloudWatchAccount?: CfnAccount;
 
   constructor(scope: Construct, id: string, props: RestApiBaseProps = { }) {
-    const restApiName = props.restApiName ?? id;
     super(scope, id, {
-      physicalName: restApiName,
+      physicalName:
+        props.restApiName ??
+        Lazy.string({
+          produce: () => Names.uniqueResourceName(this, {}),
+        }),
     });
-    this.restApiName = restApiName;
+    this.restApiName = this.physicalName;
 
     Object.defineProperty(this, RESTAPI_SYMBOL, { value: true });
   }

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.173.2

Environment details (OS name and version, etc.)

macOS

@kmkhr kmkhr added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 18, 2024
@github-actions github-actions bot added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Dec 18, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 19, 2024
@khushail khushail self-assigned this Dec 19, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-reproduction This issue needs reproduction. labels Dec 20, 2024
@khushail
Copy link
Contributor

khushail commented Dec 20, 2024

Hi @kmkhr , thanks for reaching out.

The id that is passed with Construct initialization is the physical id which is supposed to be unique in the scope of current scope. See this for further details -https://docs.aws.amazon.com/cdk/v2/guide/identifiers.html#identifiers_construct_ids

The id of a stack is also the identifier that you use to refer to it in the [AWS CDK CLI reference](https://docs.aws.amazon.com/cdk/v2/guide/cli.html).

Given ID is also used for generating Logical id.

So considering all the scenario, I think the restApiName id assignment/generation should not be changed.
However I would request you to share your feedback on the shared information as well.

cc: @ashishdhingra

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Dec 20, 2024
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 Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway closing-soon This issue will automatically close in 4 days unless further comments are made. feature-request A feature should be added or improved. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants