-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(apigatewayv2): add stage variables support for HTTP and WebSocket API #34548
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter fails with the following errors:
❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.
If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed, add Clarification Request
to a comment.
* @internal | ||
*/ | ||
protected get _stageVariables(): { [key: string]: string } | undefined { | ||
return Object.keys(this.stageVariables).length > 0 ? { ...this.stageVariables } : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why spread stageVariables into a new object?
{ ...this.stageVariables }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine we make a copy so that callers can't access x.stageVariables
to get a mutable reference to the original dict, and mutate it outside addStageVariable()
calls.
- Direct access to mutable collections makes it possible to bypass validation we would put into mutator functions
- Direct access to mutable collections makes for code that behaves differently in TypeScript vs across JSII, because in JSII there is no such thing as a reference to a mutable collection (all collections are always passed by copy across the wire)
Not strictly necessary because this is a private API and we can trust all the callers (i.e. ourselves) not to do stupid stuff (or can we? 🙃) but a good habit to get into for collection accessors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am good with this change!
Added pr/do-not-merge
so you can have some more talks about the details, feel free to remove the label whenever you're ready to merge.
* @internal | ||
*/ | ||
protected get _stageVariables(): { [key: string]: string } | undefined { | ||
return Object.keys(this.stageVariables).length > 0 ? { ...this.stageVariables } : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine we make a copy so that callers can't access x.stageVariables
to get a mutable reference to the original dict, and mutate it outside addStageVariable()
calls.
- Direct access to mutable collections makes it possible to bypass validation we would put into mutator functions
- Direct access to mutable collections makes for code that behaves differently in TypeScript vs across JSII, because in JSII there is no such thing as a reference to a mutable collection (all collections are always passed by copy across the wire)
Not strictly necessary because this is a private API and we can trust all the callers (i.e. ourselves) not to do stupid stuff (or can we? 🙃) but a good habit to get into for collection accessors.
@@ -87,4 +88,16 @@ export abstract class StageBase extends Resource implements IStage { | |||
dimensionsMap: { ApiId: this.baseApi.apiId, Stage: this.stageName }, | |||
}).attachTo(this); | |||
} | |||
|
|||
public addStageVariable(name: string, value: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this needs a docstring still
@@ -87,4 +88,16 @@ export abstract class StageBase extends Resource implements IStage { | |||
dimensionsMap: { ApiId: this.baseApi.apiId, Stage: this.stageName }, | |||
}).attachTo(this); | |||
} | |||
|
|||
public addStageVariable(name: string, value: string) { | |||
this.stageVariables[name] = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we had the checks mentioned in the interface doc string?
// @param name The name of the stage variable. Names can only contain alphanumeric characters and underscores. // @param value The value of the stage variable. Values can contain letters, numbers, and the following characters: _, ., :, /, +, -, @
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Issue
Closes #11818 .
Reason for this change
To support stage variables to HttpApi & WebSocketApi.
Description of changes
Add
stageVariables
property toWebSocketStage
&HttpStage
.Describe any new or updated permissions being added
N/A
Description of how you validated changes
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license