aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.61k stars 3.91k forks source link

EdgeFunction: Does not respect custom qualifier #27361

Closed sachitsac closed 1 year ago

sachitsac commented 1 year ago

Describe the bug

I am trying to use the experimental EdgeFunction construct. But it fails due to usage of a custom qualifier. Here's some information:

So in my custom construct ( L3 pattern ) that deploys the react app to S3, i am trying to add an edge function like this:

Default Synthesiser with qualifier

Screenshot 2023-09-30 at 12 51 09 pm

Edge auth function

MicrosoftTeams-image (3)

Distribution config

MicrosoftTeams-image (2)

Expected Behavior

Upon synthesis, the edge function stack should respect the custom qualifier name provided to the stack. Given that i am initialising the edge function from within my cloudfront stack, ( kinda like nested stack ), i should be able to use to inherit the custom qualifier.

Current Behavior

Its not respecting the custom qualifier provided upon stack initialisation.

Reproduction Steps

There will be an error trying to create the edge lambda function in the us-east-1 as its not using the custom qualifier passed to the parent Main stack.

Possible Solution

Two things i can think of:

I believe for the sake of simplicity, the first option should be the default as in most circumstances but the third offers most flexibility as we could possibly bootstrap different regions with different qualifiers.

Additional Information/Context

No response

CDK CLI Version

2.95.1

Framework Version

2.95.1

Node.js Version

18

OS

macos 14.0

Language

Typescript

Language Version

5

Other information

No response

rv2673 commented 1 year ago

@sachitsac If you want to only customize qualifier, and only use single qualifier per Stage(or App if you don't have stages).

You could set context variable, @aws-cdk/core:bootstrapQualifier, on Stage/App containing the stack with EdgeLambda or in cdk.json(if it is for entire app).

Which is where synthesizer looks for value(if not provided), before falling back to default value.

(I am not from cdk team)

sachitsac commented 1 year ago

Thanks @rv2673

I think you are right I'm passing it at the stack level. I'll try passing it at the app level. Might even resolve an issue I was having with the certificate construct where it wasn't respecting permission boundary.

Thanks

github-actions[bot] commented 1 year ago

⚠️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.

sachitsac commented 1 year ago

Closed as this is resolved by @rv2673 comment. No action needed.

rv2673 commented 1 year ago

@sachitsac I do think your suggestion for lambda stack to inherit the synthesizer from the containing stack still has merit, though maybe less prio. The context setting only works for qualifier customization, not for other customizations to the synthesizer.