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

[BUG] (type-safe-api) web acl names conflict for multiple apis in same stack with same logical id #750

Closed
tactactactactac opened this issue Apr 4, 2024 · 1 comment · Fixed by #752
Labels
bug Something isn't working needs-triage

Comments

@tactactactactac
Copy link

Describe the bug

When you create two type-safe-apis within one stack the generated web-acl name collides because both APIs will generate the same web-acl name despite being nested in distinct construct trees.

Looking at the code: https://github.com/aws/aws-pdk/blob/mainline/packages/type-safe-api/src/construct/waf/open-api-gateway-web-acl.ts#L34-L37

The web-acl name is generated from the nearest parent stack only.

Expected Behavior

When two separate api's are created within one stack the generated names will not collide.

Current Behavior

The generated web-acl names collide when you have two apis in one stack.

Reproduction Steps

  1. Define a cdk stack
  2. Define two type-safe-apis in the stack you made.
  3. Deploy the stack.

Possible Solution

Generate the web-acl names with the construct context.

Additional Information/Context

No response

PDK version used

0.23.26

What languages are you seeing this issue on?

Typescript

Environment details (OS name and version, etc.)

Mac, 13.5.2 (22G91)

@tactactactactac tactactactactac added bug Something isn't working needs-triage labels Apr 4, 2024
@cogwirrel
Copy link
Member

Thanks for raising this! We actually have a test for this case here:

it("Create 2 APIs on same stack", () => {
const stack = new Stack(PDKNag.app());
const func = new Function(stack, "Lambda", {
code: Code.fromInline("code"),
handler: "handler",
runtime: Runtime.NODEJS_16_X,
});
withTempSpec(sampleSpec, (specPath) => {
new TypeSafeRestApi(stack, "ApiTest1", {
specPath,
operationLookup,
integrations: {
testOperation: {
integration: Integrations.lambda(func),
},
},
});
new TypeSafeRestApi(stack, "ApiTest2", {
specPath,
operationLookup,
integrations: {
testOperation: {
integration: Integrations.lambda(func),
},
},
});

I suppose the difference here is that the logical ID of the TypeSafeRestApi instances are different, which means the WebACLs have a different name - the names look a bit like: <stack>--<api>-Acl-WebAcl.

I imagine you're encountering this issue when you have different APIs with the same logical ID, just nested under different constructs? As a workaround you should be able to change the logical IDs and they won't conflict.

To address this properly we should do something similar to what we do for the lambda names:

const lambdaNamePrefix = `${PDKNag.getStackPrefix(stack)
.split("/")
.join("-")
.slice(0, 40)}${this.node.addr.slice(-8).toUpperCase()}`;

Or even better we can use the newer CDK Names utility :)

@cogwirrel cogwirrel changed the title [BUG] (short issue description) [BUG] (type-safe-api) web acl names conflict for multiple apis in same stack with same logical id Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants