aws-cdk-lib 2.115.0__py3-none-any.whl → 2.116.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aws-cdk-lib might be problematic. Click here for more details.
- aws_cdk/__init__.py +801 -356
- aws_cdk/_jsii/__init__.py +1 -1
- aws_cdk/_jsii/{aws-cdk-lib@2.115.0.jsii.tgz → aws-cdk-lib@2.116.1.jsii.tgz} +0 -0
- aws_cdk/aws_apigateway/__init__.py +3 -1
- aws_cdk/aws_apigatewayv2/__init__.py +595 -222
- aws_cdk/aws_apigatewayv2_integrations/__init__.py +4 -5
- aws_cdk/aws_applicationautoscaling/__init__.py +51 -15
- aws_cdk/aws_appsync/__init__.py +14 -3
- aws_cdk/aws_autoscaling/__init__.py +6 -0
- aws_cdk/aws_b2bi/__init__.py +2445 -0
- aws_cdk/aws_cloud9/__init__.py +63 -63
- aws_cdk/aws_cloudfront/__init__.py +394 -0
- aws_cdk/aws_cloudfront/experimental/__init__.py +5 -2
- aws_cdk/aws_cloudtrail/__init__.py +90 -11
- aws_cdk/aws_cloudwatch/__init__.py +6 -6
- aws_cdk/aws_codedeploy/__init__.py +88 -15
- aws_cdk/aws_codepipeline/__init__.py +645 -0
- aws_cdk/aws_cognito/__init__.py +13 -26
- aws_cdk/aws_config/__init__.py +315 -1
- aws_cdk/aws_connect/__init__.py +532 -37
- aws_cdk/aws_controltower/__init__.py +4 -4
- aws_cdk/aws_datasync/__init__.py +6 -4
- aws_cdk/aws_dms/__init__.py +241 -131
- aws_cdk/aws_dynamodb/__init__.py +8 -0
- aws_cdk/aws_ec2/__init__.py +1030 -45
- aws_cdk/aws_ecr/__init__.py +78 -10
- aws_cdk/aws_ecs/__init__.py +210 -2
- aws_cdk/aws_ecs_patterns/__init__.py +77 -62
- aws_cdk/aws_eks/__init__.py +8 -1
- aws_cdk/aws_elasticache/__init__.py +136 -10
- aws_cdk/aws_elasticloadbalancingv2/__init__.py +10 -13
- aws_cdk/aws_emr/__init__.py +234 -17
- aws_cdk/aws_eventschemas/__init__.py +15 -13
- aws_cdk/aws_fis/__init__.py +33 -13
- aws_cdk/aws_gamelift/__init__.py +47 -0
- aws_cdk/aws_imagebuilder/__init__.py +922 -84
- aws_cdk/aws_internetmonitor/__init__.py +12 -10
- aws_cdk/aws_iot/__init__.py +26 -46
- aws_cdk/aws_iottwinmaker/__init__.py +36 -34
- aws_cdk/aws_lambda/__init__.py +19 -15
- aws_cdk/aws_lambda_nodejs/__init__.py +5 -2
- aws_cdk/aws_logs/__init__.py +6 -6
- aws_cdk/aws_opensearchservice/__init__.py +5 -3
- aws_cdk/aws_organizations/__init__.py +3 -3
- aws_cdk/aws_osis/__init__.py +17 -13
- aws_cdk/aws_rds/__init__.py +6 -0
- aws_cdk/aws_s3/__init__.py +4 -2
- aws_cdk/aws_s3outposts/__init__.py +8 -8
- aws_cdk/aws_sagemaker/__init__.py +17 -94
- aws_cdk/aws_secretsmanager/__init__.py +9 -7
- aws_cdk/aws_securityhub/__init__.py +18 -0
- aws_cdk/aws_servicecatalogappregistry/__init__.py +31 -0
- aws_cdk/aws_ses/__init__.py +58 -11
- aws_cdk/aws_sns/__init__.py +309 -10
- aws_cdk/aws_ssm/__init__.py +3 -5
- aws_cdk/aws_stepfunctions/__init__.py +335 -19
- aws_cdk/aws_stepfunctions_tasks/__init__.py +388 -38
- aws_cdk/aws_transfer/__init__.py +37 -10
- aws_cdk/custom_resources/__init__.py +443 -1
- aws_cdk/triggers/__init__.py +5 -2
- {aws_cdk_lib-2.115.0.dist-info → aws_cdk_lib-2.116.1.dist-info}/METADATA +1 -1
- {aws_cdk_lib-2.115.0.dist-info → aws_cdk_lib-2.116.1.dist-info}/RECORD +66 -65
- {aws_cdk_lib-2.115.0.dist-info → aws_cdk_lib-2.116.1.dist-info}/LICENSE +0 -0
- {aws_cdk_lib-2.115.0.dist-info → aws_cdk_lib-2.116.1.dist-info}/NOTICE +0 -0
- {aws_cdk_lib-2.115.0.dist-info → aws_cdk_lib-2.116.1.dist-info}/WHEEL +0 -0
- {aws_cdk_lib-2.115.0.dist-info → aws_cdk_lib-2.116.1.dist-info}/top_level.txt +0 -0
|
@@ -1,34 +1,459 @@
|
|
|
1
1
|
'''
|
|
2
|
-
# AWS
|
|
2
|
+
# AWS APIGatewayv2 Construct Library
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
## Table of Contents
|
|
5
|
+
|
|
6
|
+
* [Introduction](#introduction)
|
|
7
|
+
* [HTTP API](#http-api)
|
|
8
|
+
|
|
9
|
+
* [Defining HTTP APIs](#defining-http-apis)
|
|
10
|
+
* [Cross Origin Resource Sharing (CORS)](#cross-origin-resource-sharing-cors)
|
|
11
|
+
* [Publishing HTTP APIs](#publishing-http-apis)
|
|
12
|
+
* [Custom Domain](#custom-domain)
|
|
13
|
+
* [Mutual TLS](#mutual-tls-mtls)
|
|
14
|
+
* [Managing access to HTTP APIs](#managing-access-to-http-apis)
|
|
15
|
+
* [Metrics](#metrics)
|
|
16
|
+
* [VPC Link](#vpc-link)
|
|
17
|
+
* [Private Integration](#private-integration)
|
|
18
|
+
* [WebSocket API](#websocket-api)
|
|
19
|
+
|
|
20
|
+
* [Manage Connections Permission](#manage-connections-permission)
|
|
21
|
+
* [Managing access to WebSocket APIs](#managing-access-to-websocket-apis)
|
|
22
|
+
|
|
23
|
+
## Introduction
|
|
24
|
+
|
|
25
|
+
Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket
|
|
26
|
+
APIs at any scale. API developers can create APIs that access AWS or other web services, as well as data stored in the AWS Cloud.
|
|
27
|
+
As an API Gateway API developer, you can create APIs for use in your own client applications. Read the
|
|
28
|
+
[Amazon API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html).
|
|
29
|
+
|
|
30
|
+
This module supports features under [API Gateway v2](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_ApiGatewayV2.html)
|
|
31
|
+
that lets users set up Websocket and HTTP APIs.
|
|
32
|
+
REST APIs can be created using the `aws-cdk-lib/aws-apigateway` module.
|
|
33
|
+
|
|
34
|
+
HTTP and Websocket APIs use the same CloudFormation resources under the hood. However, this module separates them into two separate constructs for a more efficient abstraction since there are a number of CloudFormation properties that specifically apply only to each type of API.
|
|
35
|
+
|
|
36
|
+
## HTTP API
|
|
37
|
+
|
|
38
|
+
HTTP APIs enable creation of RESTful APIs that integrate with AWS Lambda functions, known as Lambda proxy integration,
|
|
39
|
+
or to any routable HTTP endpoint, known as HTTP proxy integration.
|
|
40
|
+
|
|
41
|
+
### Defining HTTP APIs
|
|
42
|
+
|
|
43
|
+
HTTP APIs have two fundamental concepts - Routes and Integrations.
|
|
44
|
+
|
|
45
|
+
Routes direct incoming API requests to backend resources. Routes consist of two parts: an HTTP method and a resource
|
|
46
|
+
path, such as, `GET /books`. Learn more at [Working with
|
|
47
|
+
routes](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html). Use the `ANY` method
|
|
48
|
+
to match any methods for a route that are not explicitly defined.
|
|
49
|
+
|
|
50
|
+
Integrations define how the HTTP API responds when a client reaches a specific Route. HTTP APIs support Lambda proxy
|
|
51
|
+
integration, HTTP proxy integration and, AWS service integrations, also known as private integrations. Learn more at
|
|
52
|
+
[Configuring integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations.html).
|
|
53
|
+
|
|
54
|
+
Integrations are available at the `aws-apigatewayv2-integrations` module and more information is available in that module.
|
|
55
|
+
As an early example, we have a website for a bookstore where the following code snippet configures a route `GET /books` with an HTTP proxy integration. All other HTTP method calls to `/books` route to a default lambda proxy for the bookstore.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration, HttpLambdaIntegration
|
|
59
|
+
|
|
60
|
+
# book_store_default_fn: lambda.Function
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
get_books_integration = HttpUrlIntegration("GetBooksIntegration", "https://get-books-proxy.example.com")
|
|
64
|
+
book_store_default_integration = HttpLambdaIntegration("BooksIntegration", book_store_default_fn)
|
|
65
|
+
|
|
66
|
+
http_api = apigwv2.HttpApi(self, "HttpApi")
|
|
67
|
+
|
|
68
|
+
http_api.add_routes(
|
|
69
|
+
path="/books",
|
|
70
|
+
methods=[apigwv2.HttpMethod.GET],
|
|
71
|
+
integration=get_books_integration
|
|
72
|
+
)
|
|
73
|
+
http_api.add_routes(
|
|
74
|
+
path="/books",
|
|
75
|
+
methods=[apigwv2.HttpMethod.ANY],
|
|
76
|
+
integration=book_store_default_integration
|
|
77
|
+
)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The URL to the endpoint can be retrieved via the `apiEndpoint` attribute. By default this URL is enabled for clients. Use `disableExecuteApiEndpoint` to disable it.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
http_api = apigwv2.HttpApi(self, "HttpApi",
|
|
84
|
+
disable_execute_api_endpoint=True
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The `defaultIntegration` option while defining HTTP APIs lets you create a default catch-all integration that is
|
|
89
|
+
matched when a client reaches a route that is not explicitly defined.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
apigwv2.HttpApi(self, "HttpProxyApi",
|
|
96
|
+
default_integration=HttpUrlIntegration("DefaultIntegration", "https://example.com")
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Cross Origin Resource Sharing (CORS)
|
|
101
|
+
|
|
102
|
+
[Cross-origin resource sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a browser security
|
|
103
|
+
feature that restricts HTTP requests that are initiated from scripts running in the browser. Enabling CORS will allow
|
|
104
|
+
requests to your API from a web application hosted in a domain different from your API domain.
|
|
105
|
+
|
|
106
|
+
When configured CORS for an HTTP API, API Gateway automatically sends a response to preflight `OPTIONS` requests, even
|
|
107
|
+
if there isn't an `OPTIONS` route configured. Note that, when this option is used, API Gateway will ignore CORS headers
|
|
108
|
+
returned from your backend integration. Learn more about [Configuring CORS for an HTTP
|
|
109
|
+
API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html).
|
|
110
|
+
|
|
111
|
+
The `corsPreflight` option lets you specify a CORS configuration for an API.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
apigwv2.HttpApi(self, "HttpProxyApi",
|
|
115
|
+
cors_preflight=apigwv2.CorsPreflightOptions(
|
|
116
|
+
allow_headers=["Authorization"],
|
|
117
|
+
allow_methods=[apigwv2.CorsHttpMethod.GET, apigwv2.CorsHttpMethod.HEAD, apigwv2.CorsHttpMethod.OPTIONS, apigwv2.CorsHttpMethod.POST
|
|
118
|
+
],
|
|
119
|
+
allow_origins=["*"],
|
|
120
|
+
max_age=Duration.days(10)
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Publishing HTTP APIs
|
|
126
|
+
|
|
127
|
+
A Stage is a logical reference to a lifecycle state of your API (for example, `dev`, `prod`, `beta`, or `v2`). API
|
|
128
|
+
stages are identified by their stage name. Each stage is a named reference to a deployment of the API made available for
|
|
129
|
+
client applications to call.
|
|
130
|
+
|
|
131
|
+
Use `HttpStage` to create a Stage resource for HTTP APIs. The following code sets up a Stage, whose URL is available at
|
|
132
|
+
`https://{api_id}.execute-api.{region}.amazonaws.com/beta`.
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
# api: apigwv2.HttpApi
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
apigwv2.HttpStage(self, "Stage",
|
|
139
|
+
http_api=api,
|
|
140
|
+
stage_name="beta"
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
If you omit the `stageName` will create a `$default` stage. A `$default` stage is one that is served from the base of
|
|
145
|
+
the API's URL - `https://{api_id}.execute-api.{region}.amazonaws.com/`.
|
|
146
|
+
|
|
147
|
+
Note that, `HttpApi` will always creates a `$default` stage, unless the `createDefaultStage` property is unset.
|
|
148
|
+
|
|
149
|
+
### Custom Domain
|
|
150
|
+
|
|
151
|
+
Custom domain names are simpler and more intuitive URLs that you can provide to your API users. Custom domain name are associated to API stages.
|
|
152
|
+
|
|
153
|
+
The code snippet below creates a custom domain and configures a default domain mapping for your API that maps the
|
|
154
|
+
custom domain to the `$default` stage of the API.
|
|
5
155
|
|
|
6
156
|
```python
|
|
7
|
-
import aws_cdk.
|
|
157
|
+
import aws_cdk.aws_certificatemanager as acm
|
|
158
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
159
|
+
|
|
160
|
+
# handler: lambda.Function
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
cert_arn = "arn:aws:acm:us-east-1:111111111111:certificate"
|
|
164
|
+
domain_name = "example.com"
|
|
165
|
+
|
|
166
|
+
dn = apigwv2.DomainName(self, "DN",
|
|
167
|
+
domain_name=domain_name,
|
|
168
|
+
certificate=acm.Certificate.from_certificate_arn(self, "cert", cert_arn)
|
|
169
|
+
)
|
|
170
|
+
api = apigwv2.HttpApi(self, "HttpProxyProdApi",
|
|
171
|
+
default_integration=HttpLambdaIntegration("DefaultIntegration", handler),
|
|
172
|
+
# https://${dn.domainName}/foo goes to prodApi $default stage
|
|
173
|
+
default_domain_mapping=apigwv2.DomainMappingOptions(
|
|
174
|
+
domain_name=dn,
|
|
175
|
+
mapping_key="foo"
|
|
176
|
+
)
|
|
177
|
+
)
|
|
8
178
|
```
|
|
9
179
|
|
|
10
|
-
|
|
180
|
+
To migrate a domain endpoint from one type to another, you can add a new endpoint configuration via `addEndpoint()`
|
|
181
|
+
and then configure DNS records to route traffic to the new endpoint. After that, you can remove the previous endpoint configuration.
|
|
182
|
+
Learn more at [Migrating a custom domain name](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-regional-api-custom-domain-migrate.html)
|
|
183
|
+
|
|
184
|
+
To associate a specific `Stage` to a custom domain mapping -
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
# api: apigwv2.HttpApi
|
|
188
|
+
# dn: apigwv2.DomainName
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
api.add_stage("beta",
|
|
192
|
+
stage_name="beta",
|
|
193
|
+
auto_deploy=True,
|
|
194
|
+
# https://${dn.domainName}/bar goes to the beta stage
|
|
195
|
+
domain_mapping=apigwv2.DomainMappingOptions(
|
|
196
|
+
domain_name=dn,
|
|
197
|
+
mapping_key="bar"
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
```
|
|
11
201
|
|
|
12
|
-
|
|
202
|
+
The same domain name can be associated with stages across different `HttpApi` as so -
|
|
13
203
|
|
|
14
|
-
|
|
15
|
-
|
|
204
|
+
```python
|
|
205
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
206
|
+
|
|
207
|
+
# handler: lambda.Function
|
|
208
|
+
# dn: apigwv2.DomainName
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
api_demo = apigwv2.HttpApi(self, "DemoApi",
|
|
212
|
+
default_integration=HttpLambdaIntegration("DefaultIntegration", handler),
|
|
213
|
+
# https://${dn.domainName}/demo goes to apiDemo $default stage
|
|
214
|
+
default_domain_mapping=apigwv2.DomainMappingOptions(
|
|
215
|
+
domain_name=dn,
|
|
216
|
+
mapping_key="demo"
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The `mappingKey` determines the base path of the URL with the custom domain. Each custom domain is only allowed
|
|
222
|
+
to have one API mapping with undefined `mappingKey`. If more than one API mappings are specified, `mappingKey` will be required for all of them. In the sample above, the custom domain is associated
|
|
223
|
+
with 3 API mapping resources across different APIs and Stages.
|
|
224
|
+
|
|
225
|
+
| API | Stage | URL |
|
|
226
|
+
| :------------: | :---------: | :----: |
|
|
227
|
+
| api | $default | `https://${domainName}/foo` |
|
|
228
|
+
| api | beta | `https://${domainName}/bar` |
|
|
229
|
+
| apiDemo | $default | `https://${domainName}/demo` |
|
|
230
|
+
|
|
231
|
+
You can retrieve the full domain URL with mapping key using the `domainUrl` property as so -
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
# api_demo: apigwv2.HttpApi
|
|
235
|
+
|
|
236
|
+
demo_domain_url = api_demo.default_stage.domain_url
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Mutual TLS (mTLS)
|
|
240
|
+
|
|
241
|
+
Mutual TLS can be configured to limit access to your API based by using client certificates instead of (or as an extension of) using authorization headers.
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
import aws_cdk.aws_s3 as s3
|
|
245
|
+
import aws_cdk.aws_certificatemanager as acm
|
|
246
|
+
# bucket: s3.Bucket
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
cert_arn = "arn:aws:acm:us-east-1:111111111111:certificate"
|
|
250
|
+
domain_name = "example.com"
|
|
251
|
+
|
|
252
|
+
apigwv2.DomainName(self, "DomainName",
|
|
253
|
+
domain_name=domain_name,
|
|
254
|
+
certificate=acm.Certificate.from_certificate_arn(self, "cert", cert_arn),
|
|
255
|
+
mtls=apigwv2.MTLSConfig(
|
|
256
|
+
bucket=bucket,
|
|
257
|
+
key="someca.pem",
|
|
258
|
+
version="version"
|
|
259
|
+
)
|
|
260
|
+
)
|
|
261
|
+
```
|
|
16
262
|
|
|
17
|
-
|
|
18
|
-
> as a separate package so that you can pin its version independently of the rest of the CDK. See the package:
|
|
19
|
-
>
|
|
20
|
-
> <span class="package-reference">aws-cdk-lib/aws-apigatewayv2</span>
|
|
263
|
+
Instructions for configuring your trust store can be found [here](https://aws.amazon.com/blogs/compute/introducing-mutual-tls-authentication-for-amazon-api-gateway/)
|
|
21
264
|
|
|
22
|
-
|
|
265
|
+
### Managing access to HTTP APIs
|
|
23
266
|
|
|
24
|
-
|
|
25
|
-
|
|
267
|
+
API Gateway supports multiple mechanisms for [controlling and managing access to your HTTP
|
|
268
|
+
API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-access-control.html) through authorizers.
|
|
26
269
|
|
|
27
|
-
|
|
270
|
+
These authorizers can be found in the [APIGatewayV2-Authorizers](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2_authorizers-readme.html) constructs library.
|
|
28
271
|
|
|
29
|
-
|
|
272
|
+
### Metrics
|
|
30
273
|
|
|
31
|
-
|
|
274
|
+
The API Gateway v2 service sends metrics around the performance of HTTP APIs to Amazon CloudWatch.
|
|
275
|
+
These metrics can be referred to using the metric APIs available on the `HttpApi` construct.
|
|
276
|
+
The APIs with the `metric` prefix can be used to get reference to specific metrics for this API. For example,
|
|
277
|
+
the method below refers to the client side errors metric for this API.
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
api = apigwv2.HttpApi(self, "my-api")
|
|
281
|
+
client_error_metric = api.metric_client_error()
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Please note that this will return a metric for all the stages defined in the api. It is also possible to refer to metrics for a specific Stage using
|
|
285
|
+
the `metric` methods from the `Stage` construct.
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
api = apigwv2.HttpApi(self, "my-api")
|
|
289
|
+
stage = apigwv2.HttpStage(self, "Stage",
|
|
290
|
+
http_api=api
|
|
291
|
+
)
|
|
292
|
+
client_error_metric = stage.metric_client_error()
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### VPC Link
|
|
296
|
+
|
|
297
|
+
Private integrations let HTTP APIs connect with AWS resources that are placed behind a VPC. These are usually Application
|
|
298
|
+
Load Balancers, Network Load Balancers or a Cloud Map service. The `VpcLink` construct enables this integration.
|
|
299
|
+
The following code creates a `VpcLink` to a private VPC.
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
import aws_cdk.aws_ec2 as ec2
|
|
303
|
+
import aws_cdk.aws_elasticloadbalancingv2 as elb
|
|
304
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
vpc = ec2.Vpc(self, "VPC")
|
|
308
|
+
alb = elb.ApplicationLoadBalancer(self, "AppLoadBalancer", vpc=vpc)
|
|
309
|
+
|
|
310
|
+
vpc_link = apigwv2.VpcLink(self, "VpcLink", vpc=vpc)
|
|
311
|
+
|
|
312
|
+
# Creating an HTTP ALB Integration:
|
|
313
|
+
alb_integration = HttpAlbIntegration("ALBIntegration", alb.listeners[0])
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Any existing `VpcLink` resource can be imported into the CDK app via the `VpcLink.fromVpcLinkAttributes()`.
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
import aws_cdk.aws_ec2 as ec2
|
|
320
|
+
|
|
321
|
+
# vpc: ec2.Vpc
|
|
322
|
+
|
|
323
|
+
awesome_link = apigwv2.VpcLink.from_vpc_link_attributes(self, "awesome-vpc-link",
|
|
324
|
+
vpc_link_id="us-east-1_oiuR12Abd",
|
|
325
|
+
vpc=vpc
|
|
326
|
+
)
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Private Integration
|
|
330
|
+
|
|
331
|
+
Private integrations enable integrating an HTTP API route with private resources in a VPC, such as Application Load Balancers or
|
|
332
|
+
Amazon ECS container-based applications. Using private integrations, resources in a VPC can be exposed for access by
|
|
333
|
+
clients outside of the VPC.
|
|
334
|
+
|
|
335
|
+
These integrations can be found in the [aws-apigatewayv2-integrations](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2_integrations-readme.html) constructs library.
|
|
336
|
+
|
|
337
|
+
## WebSocket API
|
|
338
|
+
|
|
339
|
+
A WebSocket API in API Gateway is a collection of WebSocket routes that are integrated with backend HTTP endpoints,
|
|
340
|
+
Lambda functions, or other AWS services. You can use API Gateway features to help you with all aspects of the API
|
|
341
|
+
lifecycle, from creation through monitoring your production APIs. [Read more](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-overview.html)
|
|
342
|
+
|
|
343
|
+
WebSocket APIs have two fundamental concepts - Routes and Integrations.
|
|
344
|
+
|
|
345
|
+
WebSocket APIs direct JSON messages to backend integrations based on configured routes. (Non-JSON messages are directed
|
|
346
|
+
to the configured `$default` route.)
|
|
347
|
+
|
|
348
|
+
Integrations define how the WebSocket API behaves when a client reaches a specific Route. Learn more at
|
|
349
|
+
[Configuring integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-integration-requests.html).
|
|
350
|
+
|
|
351
|
+
Integrations are available in the `aws-apigatewayv2-integrations` module and more information is available in that module.
|
|
352
|
+
|
|
353
|
+
To add the default WebSocket routes supported by API Gateway (`$connect`, `$disconnect` and `$default`), configure them as part of api props:
|
|
354
|
+
|
|
355
|
+
```python
|
|
356
|
+
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration
|
|
357
|
+
|
|
358
|
+
# connect_handler: lambda.Function
|
|
359
|
+
# disconnect_handler: lambda.Function
|
|
360
|
+
# default_handler: lambda.Function
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi",
|
|
364
|
+
connect_route_options=apigwv2.WebSocketRouteOptions(integration=WebSocketLambdaIntegration("ConnectIntegration", connect_handler)),
|
|
365
|
+
disconnect_route_options=apigwv2.WebSocketRouteOptions(integration=WebSocketLambdaIntegration("DisconnectIntegration", disconnect_handler)),
|
|
366
|
+
default_route_options=apigwv2.WebSocketRouteOptions(integration=WebSocketLambdaIntegration("DefaultIntegration", default_handler))
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
apigwv2.WebSocketStage(self, "mystage",
|
|
370
|
+
web_socket_api=web_socket_api,
|
|
371
|
+
stage_name="dev",
|
|
372
|
+
auto_deploy=True
|
|
373
|
+
)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
To retrieve a websocket URL and a callback URL:
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
# web_socket_stage: apigwv2.WebSocketStage
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
web_socket_uRL = web_socket_stage.url
|
|
383
|
+
# wss://${this.api.apiId}.execute-api.${s.region}.${s.urlSuffix}/${urlPath}
|
|
384
|
+
callback_uRL = web_socket_stage.callback_url
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
To add any other route:
|
|
388
|
+
|
|
389
|
+
```python
|
|
390
|
+
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration
|
|
391
|
+
|
|
392
|
+
# message_handler: lambda.Function
|
|
393
|
+
|
|
394
|
+
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi")
|
|
395
|
+
web_socket_api.add_route("sendmessage",
|
|
396
|
+
integration=WebSocketLambdaIntegration("SendMessageIntegration", message_handler)
|
|
397
|
+
)
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
To add a route that can return a result:
|
|
401
|
+
|
|
402
|
+
```python
|
|
403
|
+
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration
|
|
404
|
+
|
|
405
|
+
# message_handler: lambda.Function
|
|
406
|
+
|
|
407
|
+
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi")
|
|
408
|
+
web_socket_api.add_route("sendmessage",
|
|
409
|
+
integration=WebSocketLambdaIntegration("SendMessageIntegration", message_handler),
|
|
410
|
+
return_response=True
|
|
411
|
+
)
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
To import an existing WebSocketApi:
|
|
415
|
+
|
|
416
|
+
```python
|
|
417
|
+
web_socket_api = apigwv2.WebSocketApi.from_web_socket_api_attributes(self, "mywsapi", web_socket_id="api-1234")
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
### Manage Connections Permission
|
|
421
|
+
|
|
422
|
+
Grant permission to use API Gateway Management API of a WebSocket API by calling the `grantManageConnections` API.
|
|
423
|
+
You can use Management API to send a callback message to a connected client, get connection information, or disconnect the client. Learn more at [Use @connections commands in your backend service](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html).
|
|
424
|
+
|
|
425
|
+
```python
|
|
426
|
+
# fn: lambda.Function
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi")
|
|
430
|
+
stage = apigwv2.WebSocketStage(self, "mystage",
|
|
431
|
+
web_socket_api=web_socket_api,
|
|
432
|
+
stage_name="dev"
|
|
433
|
+
)
|
|
434
|
+
# per stage permission
|
|
435
|
+
stage.grant_management_api_access(fn)
|
|
436
|
+
# for all the stages permission
|
|
437
|
+
web_socket_api.grant_manage_connections(fn)
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Managing access to WebSocket APIs
|
|
441
|
+
|
|
442
|
+
API Gateway supports multiple mechanisms for [controlling and managing access to a WebSocket API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-control-access.html) through authorizers.
|
|
443
|
+
|
|
444
|
+
These authorizers can be found in the [APIGatewayV2-Authorizers](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigatewayv2_authorizers-readme.html) constructs library.
|
|
445
|
+
|
|
446
|
+
### API Keys
|
|
447
|
+
|
|
448
|
+
Websocket APIs also support usage of API Keys. An API Key is a key that is used to grant access to an API. These are useful for controlling and tracking access to an API, when used together with [usage plans](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html). These together allow you to configure controls around API access such as quotas and throttling, along with per-API Key metrics on usage.
|
|
449
|
+
|
|
450
|
+
To require an API Key when accessing the Websocket API:
|
|
451
|
+
|
|
452
|
+
```python
|
|
453
|
+
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi",
|
|
454
|
+
api_key_selection_expression=apigwv2.WebSocketApiKeySelectionExpression.HEADER_X_API_KEY
|
|
455
|
+
)
|
|
456
|
+
```
|
|
32
457
|
'''
|
|
33
458
|
import abc
|
|
34
459
|
import builtins
|
|
@@ -7774,7 +8199,22 @@ class CfnVpcLinkProps:
|
|
|
7774
8199
|
|
|
7775
8200
|
@jsii.enum(jsii_type="aws-cdk-lib.aws_apigatewayv2.CorsHttpMethod")
|
|
7776
8201
|
class CorsHttpMethod(enum.Enum):
|
|
7777
|
-
'''Supported CORS HTTP methods.
|
|
8202
|
+
'''Supported CORS HTTP methods.
|
|
8203
|
+
|
|
8204
|
+
:exampleMetadata: infused
|
|
8205
|
+
|
|
8206
|
+
Example::
|
|
8207
|
+
|
|
8208
|
+
apigwv2.HttpApi(self, "HttpProxyApi",
|
|
8209
|
+
cors_preflight=apigwv2.CorsPreflightOptions(
|
|
8210
|
+
allow_headers=["Authorization"],
|
|
8211
|
+
allow_methods=[apigwv2.CorsHttpMethod.GET, apigwv2.CorsHttpMethod.HEAD, apigwv2.CorsHttpMethod.OPTIONS, apigwv2.CorsHttpMethod.POST
|
|
8212
|
+
],
|
|
8213
|
+
allow_origins=["*"],
|
|
8214
|
+
max_age=Duration.days(10)
|
|
8215
|
+
)
|
|
8216
|
+
)
|
|
8217
|
+
'''
|
|
7778
8218
|
|
|
7779
8219
|
ANY = "ANY"
|
|
7780
8220
|
'''HTTP ANY.'''
|
|
@@ -7826,22 +8266,18 @@ class CorsPreflightOptions:
|
|
|
7826
8266
|
:param expose_headers: Represents a collection of exposed headers. Default: - No Expose Headers are allowed.
|
|
7827
8267
|
:param max_age: The duration that the browser should cache preflight request results. Default: Duration.seconds(0)
|
|
7828
8268
|
|
|
7829
|
-
:exampleMetadata:
|
|
8269
|
+
:exampleMetadata: infused
|
|
7830
8270
|
|
|
7831
8271
|
Example::
|
|
7832
8272
|
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
allow_methods=[apigatewayv2.CorsHttpMethod.ANY],
|
|
7842
|
-
allow_origins=["allowOrigins"],
|
|
7843
|
-
expose_headers=["exposeHeaders"],
|
|
7844
|
-
max_age=cdk.Duration.minutes(30)
|
|
8273
|
+
apigwv2.HttpApi(self, "HttpProxyApi",
|
|
8274
|
+
cors_preflight=apigwv2.CorsPreflightOptions(
|
|
8275
|
+
allow_headers=["Authorization"],
|
|
8276
|
+
allow_methods=[apigwv2.CorsHttpMethod.GET, apigwv2.CorsHttpMethod.HEAD, apigwv2.CorsHttpMethod.OPTIONS, apigwv2.CorsHttpMethod.POST
|
|
8277
|
+
],
|
|
8278
|
+
allow_origins=["*"],
|
|
8279
|
+
max_age=Duration.days(10)
|
|
8280
|
+
)
|
|
7845
8281
|
)
|
|
7846
8282
|
'''
|
|
7847
8283
|
if __debug__:
|
|
@@ -7949,21 +8385,23 @@ class DomainMappingOptions:
|
|
|
7949
8385
|
:param domain_name: The domain name for the mapping.
|
|
7950
8386
|
:param mapping_key: The API mapping key. Leave it undefined for the root path mapping. Default: - empty key for the root path mapping
|
|
7951
8387
|
|
|
7952
|
-
:exampleMetadata:
|
|
8388
|
+
:exampleMetadata: infused
|
|
7953
8389
|
|
|
7954
8390
|
Example::
|
|
7955
8391
|
|
|
7956
|
-
|
|
7957
|
-
# The values are placeholders you should change.
|
|
7958
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
8392
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
7959
8393
|
|
|
7960
|
-
#
|
|
8394
|
+
# handler: lambda.Function
|
|
8395
|
+
# dn: apigwv2.DomainName
|
|
7961
8396
|
|
|
7962
|
-
domain_mapping_options = apigatewayv2.DomainMappingOptions(
|
|
7963
|
-
domain_name=domain_name,
|
|
7964
8397
|
|
|
7965
|
-
|
|
7966
|
-
|
|
8398
|
+
api_demo = apigwv2.HttpApi(self, "DemoApi",
|
|
8399
|
+
default_integration=HttpLambdaIntegration("DefaultIntegration", handler),
|
|
8400
|
+
# https://${dn.domainName}/demo goes to apiDemo $default stage
|
|
8401
|
+
default_domain_mapping=apigwv2.DomainMappingOptions(
|
|
8402
|
+
domain_name=dn,
|
|
8403
|
+
mapping_key="demo"
|
|
8404
|
+
)
|
|
7967
8405
|
)
|
|
7968
8406
|
'''
|
|
7969
8407
|
if __debug__:
|
|
@@ -8403,16 +8841,17 @@ class HttpApiProps:
|
|
|
8403
8841
|
|
|
8404
8842
|
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
|
|
8405
8843
|
|
|
8844
|
+
# lb: elbv2.ApplicationLoadBalancer
|
|
8406
8845
|
|
|
8407
|
-
vpc = ec2.Vpc(self, "VPC")
|
|
8408
|
-
lb = elbv2.ApplicationLoadBalancer(self, "lb", vpc=vpc)
|
|
8409
8846
|
listener = lb.add_listener("listener", port=80)
|
|
8410
8847
|
listener.add_targets("target",
|
|
8411
8848
|
port=80
|
|
8412
8849
|
)
|
|
8413
8850
|
|
|
8414
8851
|
http_endpoint = apigwv2.HttpApi(self, "HttpProxyPrivateApi",
|
|
8415
|
-
default_integration=HttpAlbIntegration("DefaultIntegration", listener
|
|
8852
|
+
default_integration=HttpAlbIntegration("DefaultIntegration", listener,
|
|
8853
|
+
parameter_mapping=apigwv2.ParameterMapping().custom("myKey", "myValue")
|
|
8854
|
+
)
|
|
8416
8855
|
)
|
|
8417
8856
|
'''
|
|
8418
8857
|
if isinstance(cors_preflight, dict):
|
|
@@ -9152,18 +9591,25 @@ class HttpMethod(enum.Enum):
|
|
|
9152
9591
|
|
|
9153
9592
|
Example::
|
|
9154
9593
|
|
|
9155
|
-
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
9594
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration, HttpLambdaIntegration
|
|
9156
9595
|
|
|
9157
|
-
#
|
|
9596
|
+
# book_store_default_fn: lambda.Function
|
|
9158
9597
|
|
|
9159
|
-
|
|
9598
|
+
|
|
9599
|
+
get_books_integration = HttpUrlIntegration("GetBooksIntegration", "https://get-books-proxy.example.com")
|
|
9600
|
+
book_store_default_integration = HttpLambdaIntegration("BooksIntegration", book_store_default_fn)
|
|
9160
9601
|
|
|
9161
9602
|
http_api = apigwv2.HttpApi(self, "HttpApi")
|
|
9162
9603
|
|
|
9163
9604
|
http_api.add_routes(
|
|
9164
9605
|
path="/books",
|
|
9165
9606
|
methods=[apigwv2.HttpMethod.GET],
|
|
9166
|
-
integration=
|
|
9607
|
+
integration=get_books_integration
|
|
9608
|
+
)
|
|
9609
|
+
http_api.add_routes(
|
|
9610
|
+
path="/books",
|
|
9611
|
+
methods=[apigwv2.HttpMethod.ANY],
|
|
9612
|
+
integration=book_store_default_integration
|
|
9167
9613
|
)
|
|
9168
9614
|
'''
|
|
9169
9615
|
|
|
@@ -11330,23 +11776,26 @@ class MTLSConfig:
|
|
|
11330
11776
|
:param key: The key in S3 to look at for the trust store.
|
|
11331
11777
|
:param version: The version of the S3 object that contains your truststore. To specify a version, you must have versioning enabled for the S3 bucket. Default: - latest version
|
|
11332
11778
|
|
|
11333
|
-
:exampleMetadata:
|
|
11779
|
+
:exampleMetadata: infused
|
|
11334
11780
|
|
|
11335
11781
|
Example::
|
|
11336
11782
|
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
11340
|
-
from aws_cdk import aws_s3 as s3
|
|
11341
|
-
|
|
11783
|
+
import aws_cdk.aws_s3 as s3
|
|
11784
|
+
import aws_cdk.aws_certificatemanager as acm
|
|
11342
11785
|
# bucket: s3.Bucket
|
|
11343
11786
|
|
|
11344
|
-
m_tLSConfig = apigatewayv2.MTLSConfig(
|
|
11345
|
-
bucket=bucket,
|
|
11346
|
-
key="key",
|
|
11347
11787
|
|
|
11348
|
-
|
|
11349
|
-
|
|
11788
|
+
cert_arn = "arn:aws:acm:us-east-1:111111111111:certificate"
|
|
11789
|
+
domain_name = "example.com"
|
|
11790
|
+
|
|
11791
|
+
apigwv2.DomainName(self, "DomainName",
|
|
11792
|
+
domain_name=domain_name,
|
|
11793
|
+
certificate=acm.Certificate.from_certificate_arn(self, "cert", cert_arn),
|
|
11794
|
+
mtls=apigwv2.MTLSConfig(
|
|
11795
|
+
bucket=bucket,
|
|
11796
|
+
key="someca.pem",
|
|
11797
|
+
version="version"
|
|
11798
|
+
)
|
|
11350
11799
|
)
|
|
11351
11800
|
'''
|
|
11352
11801
|
if __debug__:
|
|
@@ -11999,23 +12448,18 @@ class VpcLink(
|
|
|
11999
12448
|
|
|
12000
12449
|
Example::
|
|
12001
12450
|
|
|
12002
|
-
import aws_cdk.
|
|
12003
|
-
|
|
12451
|
+
import aws_cdk.aws_ec2 as ec2
|
|
12452
|
+
import aws_cdk.aws_elasticloadbalancingv2 as elb
|
|
12453
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
|
|
12004
12454
|
|
|
12005
12455
|
|
|
12006
12456
|
vpc = ec2.Vpc(self, "VPC")
|
|
12457
|
+
alb = elb.ApplicationLoadBalancer(self, "AppLoadBalancer", vpc=vpc)
|
|
12458
|
+
|
|
12007
12459
|
vpc_link = apigwv2.VpcLink(self, "VpcLink", vpc=vpc)
|
|
12008
|
-
namespace = servicediscovery.PrivateDnsNamespace(self, "Namespace",
|
|
12009
|
-
name="boobar.com",
|
|
12010
|
-
vpc=vpc
|
|
12011
|
-
)
|
|
12012
|
-
service = namespace.create_service("Service")
|
|
12013
12460
|
|
|
12014
|
-
|
|
12015
|
-
|
|
12016
|
-
vpc_link=vpc_link
|
|
12017
|
-
)
|
|
12018
|
-
)
|
|
12461
|
+
# Creating an HTTP ALB Integration:
|
|
12462
|
+
alb_integration = HttpAlbIntegration("ALBIntegration", alb.listeners[0])
|
|
12019
12463
|
'''
|
|
12020
12464
|
|
|
12021
12465
|
def __init__(
|
|
@@ -12121,20 +12565,17 @@ class VpcLinkAttributes:
|
|
|
12121
12565
|
:param vpc: The VPC to which this VPC link is associated with.
|
|
12122
12566
|
:param vpc_link_id: The VPC Link id.
|
|
12123
12567
|
|
|
12124
|
-
:exampleMetadata:
|
|
12568
|
+
:exampleMetadata: infused
|
|
12125
12569
|
|
|
12126
12570
|
Example::
|
|
12127
12571
|
|
|
12128
|
-
|
|
12129
|
-
# The values are placeholders you should change.
|
|
12130
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
12131
|
-
from aws_cdk import aws_ec2 as ec2
|
|
12572
|
+
import aws_cdk.aws_ec2 as ec2
|
|
12132
12573
|
|
|
12133
12574
|
# vpc: ec2.Vpc
|
|
12134
12575
|
|
|
12135
|
-
|
|
12136
|
-
|
|
12137
|
-
|
|
12576
|
+
awesome_link = apigwv2.VpcLink.from_vpc_link_attributes(self, "awesome-vpc-link",
|
|
12577
|
+
vpc_link_id="us-east-1_oiuR12Abd",
|
|
12578
|
+
vpc=vpc
|
|
12138
12579
|
)
|
|
12139
12580
|
'''
|
|
12140
12581
|
if __debug__:
|
|
@@ -12202,23 +12643,18 @@ class VpcLinkProps:
|
|
|
12202
12643
|
|
|
12203
12644
|
Example::
|
|
12204
12645
|
|
|
12205
|
-
import aws_cdk.
|
|
12206
|
-
|
|
12646
|
+
import aws_cdk.aws_ec2 as ec2
|
|
12647
|
+
import aws_cdk.aws_elasticloadbalancingv2 as elb
|
|
12648
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
|
|
12207
12649
|
|
|
12208
12650
|
|
|
12209
12651
|
vpc = ec2.Vpc(self, "VPC")
|
|
12652
|
+
alb = elb.ApplicationLoadBalancer(self, "AppLoadBalancer", vpc=vpc)
|
|
12653
|
+
|
|
12210
12654
|
vpc_link = apigwv2.VpcLink(self, "VpcLink", vpc=vpc)
|
|
12211
|
-
namespace = servicediscovery.PrivateDnsNamespace(self, "Namespace",
|
|
12212
|
-
name="boobar.com",
|
|
12213
|
-
vpc=vpc
|
|
12214
|
-
)
|
|
12215
|
-
service = namespace.create_service("Service")
|
|
12216
12655
|
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
vpc_link=vpc_link
|
|
12220
|
-
)
|
|
12221
|
-
)
|
|
12656
|
+
# Creating an HTTP ALB Integration:
|
|
12657
|
+
alb_integration = HttpAlbIntegration("ALBIntegration", alb.listeners[0])
|
|
12222
12658
|
'''
|
|
12223
12659
|
if isinstance(subnets, dict):
|
|
12224
12660
|
subnets = _SubnetSelection_e57d76df(**subnets)
|
|
@@ -12502,20 +12938,11 @@ class WebSocketApiAttributes:
|
|
|
12502
12938
|
:param web_socket_id: The identifier of the WebSocketApi.
|
|
12503
12939
|
:param api_endpoint: The endpoint URL of the WebSocketApi. Default: - throw san error if apiEndpoint is accessed.
|
|
12504
12940
|
|
|
12505
|
-
:exampleMetadata:
|
|
12941
|
+
:exampleMetadata: infused
|
|
12506
12942
|
|
|
12507
12943
|
Example::
|
|
12508
12944
|
|
|
12509
|
-
|
|
12510
|
-
# The values are placeholders you should change.
|
|
12511
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
12512
|
-
|
|
12513
|
-
web_socket_api_attributes = apigatewayv2.WebSocketApiAttributes(
|
|
12514
|
-
web_socket_id="webSocketId",
|
|
12515
|
-
|
|
12516
|
-
# the properties below are optional
|
|
12517
|
-
api_endpoint="apiEndpoint"
|
|
12518
|
-
)
|
|
12945
|
+
web_socket_api = apigwv2.WebSocketApi.from_web_socket_api_attributes(self, "mywsapi", web_socket_id="api-1234")
|
|
12519
12946
|
'''
|
|
12520
12947
|
if __debug__:
|
|
12521
12948
|
type_hints = typing.get_type_hints(_typecheckingstub__87a97aaa032b92280dce0e4e2727c8d585344d985b7a83ba0c265ed022a4f143)
|
|
@@ -12561,15 +12988,13 @@ class WebSocketApiKeySelectionExpression(
|
|
|
12561
12988
|
):
|
|
12562
12989
|
'''Represents the currently available API Key Selection Expressions.
|
|
12563
12990
|
|
|
12564
|
-
:exampleMetadata:
|
|
12991
|
+
:exampleMetadata: infused
|
|
12565
12992
|
|
|
12566
12993
|
Example::
|
|
12567
12994
|
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
web_socket_api_key_selection_expression = apigatewayv2.WebSocketApiKeySelectionExpression("customApiKeySelector")
|
|
12995
|
+
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi",
|
|
12996
|
+
api_key_selection_expression=apigwv2.WebSocketApiKeySelectionExpression.HEADER_X_API_KEY
|
|
12997
|
+
)
|
|
12573
12998
|
'''
|
|
12574
12999
|
|
|
12575
13000
|
def __init__(self, custom_api_key_selector: builtins.str) -> None:
|
|
@@ -14557,35 +14982,30 @@ class DomainName(
|
|
|
14557
14982
|
):
|
|
14558
14983
|
'''Custom domain resource for the API.
|
|
14559
14984
|
|
|
14560
|
-
:exampleMetadata:
|
|
14985
|
+
:exampleMetadata: infused
|
|
14561
14986
|
|
|
14562
14987
|
Example::
|
|
14563
14988
|
|
|
14564
|
-
|
|
14565
|
-
|
|
14566
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
14567
|
-
from aws_cdk import aws_certificatemanager as certificatemanager
|
|
14568
|
-
from aws_cdk import aws_s3 as s3
|
|
14989
|
+
import aws_cdk.aws_certificatemanager as acm
|
|
14990
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
14569
14991
|
|
|
14570
|
-
#
|
|
14571
|
-
# certificate: certificatemanager.Certificate
|
|
14992
|
+
# handler: lambda.Function
|
|
14572
14993
|
|
|
14573
|
-
domain_name = apigatewayv2.DomainName(self, "MyDomainName",
|
|
14574
|
-
certificate=certificate,
|
|
14575
|
-
domain_name="domainName",
|
|
14576
14994
|
|
|
14577
|
-
|
|
14578
|
-
|
|
14579
|
-
endpoint_type=apigatewayv2.EndpointType.EDGE,
|
|
14580
|
-
mtls=apigatewayv2.MTLSConfig(
|
|
14581
|
-
bucket=bucket,
|
|
14582
|
-
key="key",
|
|
14995
|
+
cert_arn = "arn:aws:acm:us-east-1:111111111111:certificate"
|
|
14996
|
+
domain_name = "example.com"
|
|
14583
14997
|
|
|
14584
|
-
|
|
14585
|
-
|
|
14586
|
-
)
|
|
14587
|
-
|
|
14588
|
-
|
|
14998
|
+
dn = apigwv2.DomainName(self, "DN",
|
|
14999
|
+
domain_name=domain_name,
|
|
15000
|
+
certificate=acm.Certificate.from_certificate_arn(self, "cert", cert_arn)
|
|
15001
|
+
)
|
|
15002
|
+
api = apigwv2.HttpApi(self, "HttpProxyProdApi",
|
|
15003
|
+
default_integration=HttpLambdaIntegration("DefaultIntegration", handler),
|
|
15004
|
+
# https://${dn.domainName}/foo goes to prodApi $default stage
|
|
15005
|
+
default_domain_mapping=apigwv2.DomainMappingOptions(
|
|
15006
|
+
domain_name=dn,
|
|
15007
|
+
mapping_key="foo"
|
|
15008
|
+
)
|
|
14589
15009
|
)
|
|
14590
15010
|
'''
|
|
14591
15011
|
|
|
@@ -14742,35 +15162,30 @@ class DomainNameProps(EndpointOptions):
|
|
|
14742
15162
|
:param domain_name: The custom domain name.
|
|
14743
15163
|
:param mtls: The mutual TLS authentication configuration for a custom domain name. Default: - mTLS is not configured.
|
|
14744
15164
|
|
|
14745
|
-
:exampleMetadata:
|
|
15165
|
+
:exampleMetadata: infused
|
|
14746
15166
|
|
|
14747
15167
|
Example::
|
|
14748
15168
|
|
|
14749
|
-
|
|
14750
|
-
|
|
14751
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
14752
|
-
from aws_cdk import aws_certificatemanager as certificatemanager
|
|
14753
|
-
from aws_cdk import aws_s3 as s3
|
|
15169
|
+
import aws_cdk.aws_certificatemanager as acm
|
|
15170
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
14754
15171
|
|
|
14755
|
-
#
|
|
14756
|
-
# certificate: certificatemanager.Certificate
|
|
15172
|
+
# handler: lambda.Function
|
|
14757
15173
|
|
|
14758
|
-
domain_name_props = apigatewayv2.DomainNameProps(
|
|
14759
|
-
certificate=certificate,
|
|
14760
|
-
domain_name="domainName",
|
|
14761
15174
|
|
|
14762
|
-
|
|
14763
|
-
|
|
14764
|
-
endpoint_type=apigatewayv2.EndpointType.EDGE,
|
|
14765
|
-
mtls=apigatewayv2.MTLSConfig(
|
|
14766
|
-
bucket=bucket,
|
|
14767
|
-
key="key",
|
|
15175
|
+
cert_arn = "arn:aws:acm:us-east-1:111111111111:certificate"
|
|
15176
|
+
domain_name = "example.com"
|
|
14768
15177
|
|
|
14769
|
-
|
|
14770
|
-
|
|
14771
|
-
)
|
|
14772
|
-
|
|
14773
|
-
|
|
15178
|
+
dn = apigwv2.DomainName(self, "DN",
|
|
15179
|
+
domain_name=domain_name,
|
|
15180
|
+
certificate=acm.Certificate.from_certificate_arn(self, "cert", cert_arn)
|
|
15181
|
+
)
|
|
15182
|
+
api = apigwv2.HttpApi(self, "HttpProxyProdApi",
|
|
15183
|
+
default_integration=HttpLambdaIntegration("DefaultIntegration", handler),
|
|
15184
|
+
# https://${dn.domainName}/foo goes to prodApi $default stage
|
|
15185
|
+
default_domain_mapping=apigwv2.DomainMappingOptions(
|
|
15186
|
+
domain_name=dn,
|
|
15187
|
+
mapping_key="foo"
|
|
15188
|
+
)
|
|
14774
15189
|
)
|
|
14775
15190
|
'''
|
|
14776
15191
|
if isinstance(mtls, dict):
|
|
@@ -14890,19 +15305,18 @@ class HttpApi(
|
|
|
14890
15305
|
|
|
14891
15306
|
Example::
|
|
14892
15307
|
|
|
14893
|
-
from aws_cdk.aws_apigatewayv2_integrations import
|
|
15308
|
+
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
|
|
14894
15309
|
|
|
14895
|
-
#
|
|
15310
|
+
# books_default_fn: lambda.Function
|
|
14896
15311
|
|
|
14897
|
-
|
|
14898
|
-
listener.add_targets("target",
|
|
14899
|
-
port=80
|
|
14900
|
-
)
|
|
15312
|
+
books_integration = HttpLambdaIntegration("BooksIntegration", books_default_fn)
|
|
14901
15313
|
|
|
14902
|
-
|
|
14903
|
-
|
|
14904
|
-
|
|
14905
|
-
|
|
15314
|
+
http_api = apigwv2.HttpApi(self, "HttpApi")
|
|
15315
|
+
|
|
15316
|
+
http_api.add_routes(
|
|
15317
|
+
path="/books",
|
|
15318
|
+
methods=[apigwv2.HttpMethod.GET],
|
|
15319
|
+
integration=books_integration
|
|
14906
15320
|
)
|
|
14907
15321
|
'''
|
|
14908
15322
|
|
|
@@ -15677,28 +16091,21 @@ class HttpStageOptions(StageOptions):
|
|
|
15677
16091
|
:param throttle: Throttle settings for the routes of this stage. Default: - no throttling configuration
|
|
15678
16092
|
:param stage_name: The name of the stage. See ``StageName`` class for more details. Default: '$default' the default stage of the API. This stage will have the URL at the root of the API endpoint.
|
|
15679
16093
|
|
|
15680
|
-
:exampleMetadata:
|
|
16094
|
+
:exampleMetadata: infused
|
|
15681
16095
|
|
|
15682
16096
|
Example::
|
|
15683
16097
|
|
|
15684
|
-
#
|
|
15685
|
-
#
|
|
15686
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
15687
|
-
|
|
15688
|
-
# domain_name: apigatewayv2.DomainName
|
|
16098
|
+
# api: apigwv2.HttpApi
|
|
16099
|
+
# dn: apigwv2.DomainName
|
|
15689
16100
|
|
|
15690
|
-
http_stage_options = apigatewayv2.HttpStageOptions(
|
|
15691
|
-
auto_deploy=False,
|
|
15692
|
-
domain_mapping=apigatewayv2.DomainMappingOptions(
|
|
15693
|
-
domain_name=domain_name,
|
|
15694
16101
|
|
|
15695
|
-
|
|
15696
|
-
|
|
15697
|
-
|
|
15698
|
-
|
|
15699
|
-
|
|
15700
|
-
|
|
15701
|
-
|
|
16102
|
+
api.add_stage("beta",
|
|
16103
|
+
stage_name="beta",
|
|
16104
|
+
auto_deploy=True,
|
|
16105
|
+
# https://${dn.domainName}/bar goes to the beta stage
|
|
16106
|
+
domain_mapping=apigwv2.DomainMappingOptions(
|
|
16107
|
+
domain_name=dn,
|
|
16108
|
+
mapping_key="bar"
|
|
15702
16109
|
)
|
|
15703
16110
|
)
|
|
15704
16111
|
'''
|
|
@@ -15801,33 +16208,16 @@ class HttpStageProps(HttpStageOptions):
|
|
|
15801
16208
|
:param stage_name: The name of the stage. See ``StageName`` class for more details. Default: '$default' the default stage of the API. This stage will have the URL at the root of the API endpoint.
|
|
15802
16209
|
:param http_api: The HTTP API to which this stage is associated.
|
|
15803
16210
|
|
|
15804
|
-
:exampleMetadata:
|
|
16211
|
+
:exampleMetadata: infused
|
|
15805
16212
|
|
|
15806
16213
|
Example::
|
|
15807
16214
|
|
|
15808
|
-
#
|
|
15809
|
-
# The values are placeholders you should change.
|
|
15810
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
16215
|
+
# api: apigwv2.HttpApi
|
|
15811
16216
|
|
|
15812
|
-
# domain_name: apigatewayv2.DomainName
|
|
15813
|
-
# http_api: apigatewayv2.HttpApi
|
|
15814
|
-
|
|
15815
|
-
http_stage_props = apigatewayv2.HttpStageProps(
|
|
15816
|
-
http_api=http_api,
|
|
15817
|
-
|
|
15818
|
-
# the properties below are optional
|
|
15819
|
-
auto_deploy=False,
|
|
15820
|
-
domain_mapping=apigatewayv2.DomainMappingOptions(
|
|
15821
|
-
domain_name=domain_name,
|
|
15822
16217
|
|
|
15823
|
-
|
|
15824
|
-
|
|
15825
|
-
|
|
15826
|
-
stage_name="stageName",
|
|
15827
|
-
throttle=apigatewayv2.ThrottleSettings(
|
|
15828
|
-
burst_limit=123,
|
|
15829
|
-
rate_limit=123
|
|
15830
|
-
)
|
|
16218
|
+
apigwv2.HttpStage(self, "Stage",
|
|
16219
|
+
http_api=api,
|
|
16220
|
+
stage_name="beta"
|
|
15831
16221
|
)
|
|
15832
16222
|
'''
|
|
15833
16223
|
if isinstance(domain_mapping, dict):
|
|
@@ -16708,33 +17098,16 @@ class HttpStage(
|
|
|
16708
17098
|
'''Represents a stage where an instance of the API is deployed.
|
|
16709
17099
|
|
|
16710
17100
|
:resource: AWS::ApiGatewayV2::Stage
|
|
16711
|
-
:exampleMetadata:
|
|
17101
|
+
:exampleMetadata: infused
|
|
16712
17102
|
|
|
16713
17103
|
Example::
|
|
16714
17104
|
|
|
16715
|
-
#
|
|
16716
|
-
# The values are placeholders you should change.
|
|
16717
|
-
from aws_cdk import aws_apigatewayv2 as apigatewayv2
|
|
16718
|
-
|
|
16719
|
-
# domain_name: apigatewayv2.DomainName
|
|
16720
|
-
# http_api: apigatewayv2.HttpApi
|
|
16721
|
-
|
|
16722
|
-
http_stage = apigatewayv2.HttpStage(self, "MyHttpStage",
|
|
16723
|
-
http_api=http_api,
|
|
17105
|
+
# api: apigwv2.HttpApi
|
|
16724
17106
|
|
|
16725
|
-
# the properties below are optional
|
|
16726
|
-
auto_deploy=False,
|
|
16727
|
-
domain_mapping=apigatewayv2.DomainMappingOptions(
|
|
16728
|
-
domain_name=domain_name,
|
|
16729
17107
|
|
|
16730
|
-
|
|
16731
|
-
|
|
16732
|
-
|
|
16733
|
-
stage_name="stageName",
|
|
16734
|
-
throttle=apigatewayv2.ThrottleSettings(
|
|
16735
|
-
burst_limit=123,
|
|
16736
|
-
rate_limit=123
|
|
16737
|
-
)
|
|
17108
|
+
apigwv2.HttpStage(self, "Stage",
|
|
17109
|
+
http_api=api,
|
|
17110
|
+
stage_name="beta"
|
|
16738
17111
|
)
|
|
16739
17112
|
'''
|
|
16740
17113
|
|