Skip to content

Commit f7faffe

Browse files
authored
feat: implement UsagePlan and ApiKey support in L2 constructs for aws-apigatewayv2 (WebSocketApi) (#35060)
### Issue # (if applicable) Closes #28756. ### Reason for this change Couldn't create `UsagePlans` and `ApiKeys` for `WebSocketApi` (`apigatewayv2`) using L2 constructs, cause these 2 features were supported only by `RestApi` (`apigatewayv1`). ### Description of changes `HttpApi`(`apigatewayv2`) doesn't permit creating `UsagePlans` or `ApiKeys` in any way, so bringing these functionalities from `apigatewayv1` to `apigatewayv2` is possible only for `WebSocketApi`. - Added `UsagePlan` and `ApiKey` files in `aws-apigatewayv2/lib/websocket` folder - Implemented needed interfaces, classes and methods very similar to what was written for `RestApi` (`apigatewayv1`) - Included explicit dependency management between components for proper _CloudFormation_ deployment order - Added new _JSDoc_ in order to be able to build the project ### Describe any new or updated permissions being added N/A ### Description of how you validated changes - Tested manually by deploying a stack containing and linking the new features - Wrote unit and integration tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent aa1f7df commit f7faffe

15 files changed

+2649
-0
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/websocket/integ.usage-plan.js.snapshot/WebSocketUsagePlanIntegDefaultTestDeployAssert17052BCC.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/websocket/integ.usage-plan.js.snapshot/WebSocketUsagePlanIntegDefaultTestDeployAssert17052BCC.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/websocket/integ.usage-plan.js.snapshot/aws-cdk-aws-apigatewayv2-websocket-usage-plan.assets.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{
2+
"Resources": {
3+
"WebSocketApi34BCF99B": {
4+
"Type": "AWS::ApiGatewayV2::Api",
5+
"Properties": {
6+
"Name": "WebSocketApi",
7+
"ProtocolType": "WEBSOCKET",
8+
"RouteSelectionExpression": "$request.body.action"
9+
}
10+
},
11+
"WebSocketStageC46B7E43": {
12+
"Type": "AWS::ApiGatewayV2::Stage",
13+
"Properties": {
14+
"ApiId": {
15+
"Ref": "WebSocketApi34BCF99B"
16+
},
17+
"StageName": "dev"
18+
}
19+
},
20+
"ApiKeyF9DDEE66": {
21+
"Type": "AWS::ApiGateway::ApiKey",
22+
"Properties": {
23+
"CustomerId": "my-customer",
24+
"Description": "Basic api-key",
25+
"Enabled": true,
26+
"GenerateDistinctId": true,
27+
"Name": "my-api-key",
28+
"Value": "MyApiKeyThatIsAtLeast20Characters"
29+
}
30+
},
31+
"UsagePlanC18B28F1": {
32+
"Type": "AWS::ApiGateway::UsagePlan",
33+
"Properties": {
34+
"ApiStages": [
35+
{
36+
"ApiId": {
37+
"Ref": "WebSocketApi34BCF99B"
38+
},
39+
"Stage": "dev"
40+
},
41+
{
42+
"ApiId": {
43+
"Ref": "WebSocketApi34BCF99B"
44+
},
45+
"Stage": "dev2"
46+
}
47+
],
48+
"Description": "Basic usage plan",
49+
"Quota": {
50+
"Limit": 10000,
51+
"Offset": 1,
52+
"Period": "MONTH"
53+
},
54+
"Throttle": {
55+
"BurstLimit": 200,
56+
"RateLimit": 100
57+
},
58+
"UsagePlanName": "WebSocketUsagePlan"
59+
},
60+
"DependsOn": [
61+
"WebSocketApi34BCF99B",
62+
"WebSocketStageC46B7E43"
63+
]
64+
},
65+
"UsagePlanUsagePlanKeyResourceawscdkawsapigatewayv2websocketusageplanApiKey13D28EDFF7C5F9B8": {
66+
"Type": "AWS::ApiGateway::UsagePlanKey",
67+
"Properties": {
68+
"KeyId": {
69+
"Ref": "ApiKeyF9DDEE66"
70+
},
71+
"KeyType": "API_KEY",
72+
"UsagePlanId": {
73+
"Ref": "UsagePlanC18B28F1"
74+
}
75+
},
76+
"DependsOn": [
77+
"WebSocketApi34BCF99B",
78+
"WebSocketStageC46B7E43"
79+
]
80+
},
81+
"WebSocketStage281A2E5CC": {
82+
"Type": "AWS::ApiGatewayV2::Stage",
83+
"Properties": {
84+
"ApiId": {
85+
"Ref": "WebSocketApi34BCF99B"
86+
},
87+
"StageName": "dev2"
88+
}
89+
},
90+
"WebSocketStage327374806": {
91+
"Type": "AWS::ApiGatewayV2::Stage",
92+
"Properties": {
93+
"ApiId": {
94+
"Ref": "WebSocketApi34BCF99B"
95+
},
96+
"StageName": "dev3"
97+
}
98+
},
99+
"RateLimitedApiKeyC2569A4F": {
100+
"Type": "AWS::ApiGateway::ApiKey",
101+
"Properties": {
102+
"CustomerId": "my-customer",
103+
"Description": "Basic rate-limited-api-key",
104+
"Enabled": true,
105+
"GenerateDistinctId": true,
106+
"Name": "my-rate-limited-api-key",
107+
"Value": "MyRateLimitedApiKeyThatIsAtLeast20Characters"
108+
}
109+
},
110+
"RateLimitedApiKeyUsagePlanResource1CA5546B": {
111+
"Type": "AWS::ApiGateway::UsagePlan",
112+
"Properties": {
113+
"ApiStages": [
114+
{
115+
"ApiId": {
116+
"Ref": "WebSocketApi34BCF99B"
117+
},
118+
"Stage": "dev3"
119+
}
120+
],
121+
"Quota": {
122+
"Limit": 10000,
123+
"Offset": 1,
124+
"Period": "MONTH"
125+
},
126+
"Throttle": {
127+
"BurstLimit": 200,
128+
"RateLimit": 100
129+
}
130+
},
131+
"DependsOn": [
132+
"WebSocketApi34BCF99B",
133+
"WebSocketStage327374806"
134+
]
135+
},
136+
"RateLimitedApiKeyUsagePlanResourceUsagePlanKeyResourceawscdkawsapigatewayv2websocketusageplanRateLimitedApiKey4FFB7A4516024339": {
137+
"Type": "AWS::ApiGateway::UsagePlanKey",
138+
"Properties": {
139+
"KeyId": {
140+
"Ref": "RateLimitedApiKeyC2569A4F"
141+
},
142+
"KeyType": "API_KEY",
143+
"UsagePlanId": {
144+
"Ref": "RateLimitedApiKeyUsagePlanResource1CA5546B"
145+
}
146+
},
147+
"DependsOn": [
148+
"WebSocketApi34BCF99B",
149+
"WebSocketStage327374806"
150+
]
151+
}
152+
},
153+
"Parameters": {
154+
"BootstrapVersion": {
155+
"Type": "AWS::SSM::Parameter::Value<String>",
156+
"Default": "/cdk-bootstrap/hnb659fds/version",
157+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
158+
}
159+
},
160+
"Rules": {
161+
"CheckBootstrapVersion": {
162+
"Assertions": [
163+
{
164+
"Assert": {
165+
"Fn::Not": [
166+
{
167+
"Fn::Contains": [
168+
[
169+
"1",
170+
"2",
171+
"3",
172+
"4",
173+
"5"
174+
],
175+
{
176+
"Ref": "BootstrapVersion"
177+
}
178+
]
179+
}
180+
]
181+
},
182+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
183+
}
184+
]
185+
}
186+
}
187+
}

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/websocket/integ.usage-plan.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2/test/websocket/integ.usage-plan.js.snapshot/integ.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)