See: Description
| Interface | Description |
|---|---|
| AddRoutesOptions |
(experimental) Options for the Route with Integration resoruce.
|
| ApiMappingAttributes |
(experimental) The attributes used to import existing ApiMapping.
|
| ApiMappingProps |
(experimental) Properties used to create the ApiMapping resource.
|
| BatchHttpRouteOptions |
(experimental) Options used when configuring multiple routes, at once.
|
| CfnApi.BodyS3LocationProperty | |
| CfnApi.CorsProperty | |
| CfnApiGatewayManagedOverrides.AccessLogSettingsProperty | |
| CfnApiGatewayManagedOverrides.IntegrationOverridesProperty | |
| CfnApiGatewayManagedOverrides.RouteOverridesProperty | |
| CfnApiGatewayManagedOverrides.RouteSettingsProperty | |
| CfnApiGatewayManagedOverrides.StageOverridesProperty | |
| CfnApiGatewayManagedOverridesProps |
Properties for defining a `AWS::ApiGatewayV2::ApiGatewayManagedOverrides`.
|
| CfnApiMappingProps |
Properties for defining a `AWS::ApiGatewayV2::ApiMapping`.
|
| CfnApiProps |
Properties for defining a `AWS::ApiGatewayV2::Api`.
|
| CfnAuthorizer.JWTConfigurationProperty | |
| CfnAuthorizerProps |
Properties for defining a `AWS::ApiGatewayV2::Authorizer`.
|
| CfnDeploymentProps |
Properties for defining a `AWS::ApiGatewayV2::Deployment`.
|
| CfnDomainName.DomainNameConfigurationProperty | |
| CfnDomainName.MutualTlsAuthenticationProperty | |
| CfnDomainNameProps |
Properties for defining a `AWS::ApiGatewayV2::DomainName`.
|
| CfnIntegration.ResponseParameterListProperty | |
| CfnIntegration.ResponseParameterProperty | |
| CfnIntegration.TlsConfigProperty | |
| CfnIntegrationProps |
Properties for defining a `AWS::ApiGatewayV2::Integration`.
|
| CfnIntegrationResponseProps |
Properties for defining a `AWS::ApiGatewayV2::IntegrationResponse`.
|
| CfnModelProps |
Properties for defining a `AWS::ApiGatewayV2::Model`.
|
| CfnRoute.ParameterConstraintsProperty | |
| CfnRouteProps |
Properties for defining a `AWS::ApiGatewayV2::Route`.
|
| CfnRouteResponse.ParameterConstraintsProperty | |
| CfnRouteResponseProps |
Properties for defining a `AWS::ApiGatewayV2::RouteResponse`.
|
| CfnStage.AccessLogSettingsProperty | |
| CfnStage.RouteSettingsProperty | |
| CfnStageProps |
Properties for defining a `AWS::ApiGatewayV2::Stage`.
|
| CfnVpcLinkProps |
Properties for defining a `AWS::ApiGatewayV2::VpcLink`.
|
| CorsPreflightOptions |
(experimental) Options for the CORS Configuration.
|
| DomainMappingOptions |
(experimental) Options for DomainMapping.
|
| DomainNameAttributes |
(experimental) custom domain name attributes.
|
| DomainNameProps |
(experimental) properties used for creating the DomainName.
|
| HttpApiAttributes |
(experimental) Attributes for importing an HttpApi into the CDK.
|
| HttpApiProps |
(experimental) Properties to initialize an instance of `HttpApi`.
|
| HttpAuthorizerAttributes |
(experimental) Reference to an http authorizer.
|
| HttpAuthorizerProps |
(experimental) Properties to initialize an instance of `HttpAuthorizer`.
|
| HttpIntegrationProps |
(experimental) The integration properties.
|
| HttpRouteAuthorizerBindOptions |
(experimental) Input to the bind() operation, that binds an authorizer to a route.
|
| HttpRouteAuthorizerConfig |
(experimental) Results of binding an authorizer to an http route.
|
| HttpRouteIntegrationBindOptions |
(experimental) Options to the HttpRouteIntegration during its bind operation.
|
| HttpRouteIntegrationConfig |
(experimental) Config returned back as a result of the bind.
|
| HttpRouteProps |
(experimental) Properties to initialize a new Route.
|
| HttpStageAttributes |
(experimental) The attributes used to import existing HttpStage.
|
| HttpStageOptions |
(experimental) The options to create a new Stage for an HTTP API.
|
| HttpStageProps |
(experimental) Properties to initialize an instance of `HttpStage`.
|
| IApi |
(experimental) Represents a API Gateway HTTP/WebSocket API.
|
| IApi.Jsii$Default |
Internal default implementation for
IApi. |
| IApiMapping |
(experimental) Represents an ApiGatewayV2 ApiMapping resource.
|
| IApiMapping.Jsii$Default |
Internal default implementation for
IApiMapping. |
| IAuthorizer |
(experimental) Represents an Authorizer.
|
| IAuthorizer.Jsii$Default |
Internal default implementation for
IAuthorizer. |
| IDomainName |
(experimental) Represents an APIGatewayV2 DomainName.
|
| IDomainName.Jsii$Default |
Internal default implementation for
IDomainName. |
| IHttpApi |
(experimental) Represents an HTTP API.
|
| IHttpApi.Jsii$Default |
Internal default implementation for
IHttpApi. |
| IHttpAuthorizer |
(experimental) An authorizer for HTTP APIs.
|
| IHttpAuthorizer.Jsii$Default |
Internal default implementation for
IHttpAuthorizer. |
| IHttpIntegration |
(experimental) Represents an Integration for an HTTP API.
|
| IHttpIntegration.Jsii$Default |
Internal default implementation for
IHttpIntegration. |
| IHttpRoute |
(experimental) Represents a Route for an HTTP API.
|
| IHttpRoute.Jsii$Default |
Internal default implementation for
IHttpRoute. |
| IHttpRouteAuthorizer |
(experimental) An authorizer that can attach to an Http Route.
|
| IHttpRouteAuthorizer.Jsii$Default |
Internal default implementation for
IHttpRouteAuthorizer. |
| IHttpRouteIntegration |
(experimental) The interface that various route integration classes will inherit.
|
| IHttpRouteIntegration.Jsii$Default |
Internal default implementation for
IHttpRouteIntegration. |
| IHttpStage |
(experimental) Represents the HttpStage.
|
| IHttpStage.Jsii$Default |
Internal default implementation for
IHttpStage. |
| IIntegration |
(experimental) Represents an integration to an API Route.
|
| IIntegration.Jsii$Default |
Internal default implementation for
IIntegration. |
| IRoute |
(experimental) Represents a route.
|
| IRoute.Jsii$Default |
Internal default implementation for
IRoute. |
| IStage |
(experimental) Represents a Stage.
|
| IStage.Jsii$Default |
Internal default implementation for
IStage. |
| IVpcLink |
(experimental) Represents an API Gateway VpcLink.
|
| IVpcLink.Jsii$Default |
Internal default implementation for
IVpcLink. |
| IWebSocketApi |
(experimental) Represents a WebSocket API.
|
| IWebSocketApi.Jsii$Default |
Internal default implementation for
IWebSocketApi. |
| IWebSocketIntegration |
(experimental) Represents an Integration for an WebSocket API.
|
| IWebSocketIntegration.Jsii$Default |
Internal default implementation for
IWebSocketIntegration. |
| IWebSocketRoute |
(experimental) Represents a Route for an WebSocket API.
|
| IWebSocketRoute.Jsii$Default |
Internal default implementation for
IWebSocketRoute. |
| IWebSocketRouteIntegration |
(experimental) The interface that various route integration classes will inherit.
|
| IWebSocketRouteIntegration.Jsii$Default |
Internal default implementation for
IWebSocketRouteIntegration. |
| IWebSocketStage |
(experimental) Represents the WebSocketStage.
|
| IWebSocketStage.Jsii$Default |
Internal default implementation for
IWebSocketStage. |
| StageAttributes |
(experimental) The attributes used to import existing Stage.
|
| StageOptions |
(experimental) Options required to create a new stage.
|
| VpcLinkAttributes |
(experimental) Attributes when importing a new VpcLink.
|
| VpcLinkProps |
(experimental) Properties for a VpcLink.
|
| WebSocketApiProps |
(experimental) Props for WebSocket API.
|
| WebSocketIntegrationProps |
(experimental) The integration properties.
|
| WebSocketRouteIntegrationBindOptions |
(experimental) Options to the WebSocketRouteIntegration during its bind operation.
|
| WebSocketRouteIntegrationConfig |
(experimental) Config returned back as a result of the bind.
|
| WebSocketRouteOptions |
(experimental) Options used to add route to the API.
|
| WebSocketRouteProps |
(experimental) Properties to initialize a new Route.
|
| WebSocketStageAttributes |
(experimental) The attributes used to import existing WebSocketStage.
|
| WebSocketStageProps |
(experimental) Properties to initialize an instance of `WebSocketStage`.
|
| Enum | Description |
|---|---|
| CorsHttpMethod |
(experimental) Supported CORS HTTP methods.
|
| HttpAuthorizerType |
(experimental) Supported Authorizer types.
|
| HttpConnectionType |
(experimental) Supported connection types.
|
| HttpIntegrationType |
(experimental) Supported integration types.
|
| HttpMethod |
(experimental) Supported HTTP methods.
|
| WebSocketIntegrationType |
(experimental) WebSocket Integration Types.
|
---
Features | Stability
-------------------------------------------|--------------------------------------------------------
CFN Resources |
Higher level constructs for HTTP APIs |
Higher level constructs for Websocket APIs |
CFN Resources: All classes with the
Cfnprefix in this module (CFN Resources) are always stable and safe to use.
Experimental: Higher level constructs in this module that are marked as experimental are under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.
Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket 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. As an API Gateway API developer, you can create APIs for use in your own client applications. Read the Amazon API Gateway Developer Guide.
This module supports features under API Gateway v2
that lets users set up Websocket and HTTP APIs.
REST APIs can be created using the @aws-cdk/aws-apigateway module.
HTTP APIs enable creation of RESTful APIs that integrate with AWS Lambda functions, known as Lambda proxy integration, or to any routable HTTP endpoint, known as HTTP proxy integration.
HTTP APIs have two fundamental concepts - Routes and Integrations.
Routes direct incoming API requests to backend resources. Routes consist of two parts: an HTTP method and a resource
path, such as, GET /books. Learn more at Working with
routes. Use the ANY method
to match any methods for a route that are not explicitly defined.
Integrations define how the HTTP API responds when a client reaches a specific Route. HTTP APIs support Lambda proxy integration, HTTP proxy integration and, AWS service integrations, also known as private integrations. Learn more at Configuring integrations.
Integrations are available at the aws-apigatewayv2-integrations module and more information is available in that module.
As an early example, the following code snippet configures a route GET /books with an HTTP proxy integration all
configures all other HTTP method calls to /books to a lambda proxy.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object getBooksIntegration = HttpProxyIntegration.Builder.create()
.url("https://get-books-proxy.myproxy.internal")
.build();
Object booksDefaultFn = Function.Builder.create(stack, "BooksDefaultFn")....build();
Object booksDefaultIntegration = LambdaProxyIntegration.Builder.create()
.handler(booksDefaultFn)
.build();
Object httpApi = new HttpApi(stack, "HttpApi");
httpApi.addRoutes(Map.of(
"path", "/books",
"methods", asList(HttpMethod.getGET()),
"integration", getBooksIntegration));
httpApi.addRoutes(Map.of(
"path", "/books",
"methods", asList(HttpMethod.getANY()),
"integration", booksDefaultIntegration));
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.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object httpApi = HttpApi.Builder.create(stack, "HttpApi")
.disableExecuteApiEndpoint(true)
.build();
The defaultIntegration option while defining HTTP APIs lets you create a default catch-all integration that is
matched when a client reaches a route that is not explicitly defined.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
HttpApi.Builder.create(stack, "HttpProxyApi")
.defaultIntegration(HttpProxyIntegration.Builder.create()
.url("http://example.com")
.build())
.build();
Cross-origin resource sharing (CORS) is a browser security feature that restricts HTTP requests that are initiated from scripts running in the browser. Enabling CORS will allow requests to your API from a web application hosted in a domain different from your API domain.
When configured CORS for an HTTP API, API Gateway automatically sends a response to preflight OPTIONS requests, even
if there isn't an OPTIONS route configured. Note that, when this option is used, API Gateway will ignore CORS headers
returned from your backend integration. Learn more about Configuring CORS for an HTTP
API.
The corsPreflight option lets you specify a CORS configuration for an API.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
HttpApi.Builder.create(stack, "HttpProxyApi")
.corsPreflight(Map.of(
"allowHeaders", asList("Authorization"),
"allowMethods", asList(CorsHttpMethod.getGET(), CorsHttpMethod.getHEAD(), CorsHttpMethod.getOPTIONS(), CorsHttpMethod.getPOST()),
"allowOrigins", asList("*"),
"maxAge", Duration.days(10)))
.build();
A Stage is a logical reference to a lifecycle state of your API (for example, dev, prod, beta, or v2). API
stages are identified by their stage name. Each stage is a named reference to a deployment of the API made available for
client applications to call.
Use HttpStage to create a Stage resource for HTTP APIs. The following code sets up a Stage, whose URL is available at
https://{api_id}.execute-api.{region}.amazonaws.com/beta.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
HttpStage.Builder.create(stack, "Stage")
.httpApi(api)
.stageName("beta")
.build();
If you omit the stageName will create a $default stage. A $default stage is one that is served from the base of
the API's URL - https://{api_id}.execute-api.{region}.amazonaws.com/.
Note that, HttpApi will always creates a $default stage, unless the createDefaultStage property is unset.
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.
The code snippet below creates a custom domain and configures a default domain mapping for your API that maps the
custom domain to the $default stage of the API.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
String certArn = "arn:aws:acm:us-east-1:111111111111:certificate";
String domainName = "example.com";
Object dn = DomainName.Builder.create(stack, "DN")
.domainName(domainName)
.certificate(acm.Certificate.fromCertificateArn(stack, "cert", certArn))
.build();
Object api = HttpApi.Builder.create(stack, "HttpProxyProdApi")
.defaultIntegration(LambdaProxyIntegration.Builder.create().handler(handler).build())
// https://${dn.domainName}/foo goes to prodApi $default stage
.defaultDomainMapping(Map.of(
"domainName", dn,
"mappingKey", "foo"))
.build();
To associate a specific Stage to a custom domain mapping -
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
api.addStage("beta", Map.of(
"stageName", "beta",
"autoDeploy", true,
// https://${dn.domainName}/bar goes to the beta stage
"domainMapping", Map.of(
"domainName", dn,
"mappingKey", "bar")));
The same domain name can be associated with stages across different HttpApi as so -
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object apiDemo = HttpApi.Builder.create(stack, "DemoApi")
.defaultIntegration(LambdaProxyIntegration.Builder.create().handler(handler).build())
// https://${dn.domainName}/demo goes to apiDemo $default stage
.defaultDomainMapping(Map.of(
"domainName", dn,
"mappingKey", "demo"))
.build();
The mappingKey determines the base path of the URL with the custom domain. Each custom domain is only allowed
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
with 3 API mapping resources across different APIs and Stages.
| API | Stage | URL |
| :------------: | :---------: | :----: |
| api | $default | https://${domainName}/foo |
| api | beta | https://${domainName}/bar |
| apiDemo | $default | https://${domainName}/demo |
API Gateway supports multiple mechanisms for controlling and managing access to your HTTP API through authorizers.
These authorizers can be found in the APIGatewayV2-Authorizers constructs library.
The API Gateway v2 service sends metrics around the performance of HTTP APIs to Amazon CloudWatch.
These metrics can be referred to using the metric APIs available on the HttpApi construct.
The APIs with the metric prefix can be used to get reference to specific metrics for this API. For example,
the method below refers to the client side errors metric for this API.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object api = new HttpApi(stack, "my-api"); Object clientErrorMetric = api.metricClientError();
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
the metric methods from the Stage construct.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object api = new HttpApi(stack, "my-api");
Object stage = HttpStage.Builder.create(stack, "Stage")
.httpApi(api)
.build();
Object clientErrorMetric = stage.metricClientError();
Private integrations let HTTP APIs connect with AWS resources that are placed behind a VPC. These are usually Application
Load Balancers, Network Load Balancers or a Cloud Map service. The VpcLink construct enables this integration.
The following code creates a VpcLink to a private VPC.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object vpc = new Vpc(stack, "VPC"); Object vpcLink = VpcLink.Builder.create(stack, "VpcLink").vpc(vpc).build();
Any existing VpcLink resource can be imported into the CDK app via the VpcLink.fromVpcLinkId().
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object awesomeLink = VpcLink.fromVpcLinkId(stack, "awesome-vpc-link", "us-east-1_oiuR12Abd");
Private integrations enable integrating an HTTP API route with private resources in a VPC, such as Application Load Balancers or Amazon ECS container-based applications. Using private integrations, resources in a VPC can be exposed for access by clients outside of the VPC.
These integrations can be found in the APIGatewayV2-Integrations constructs library.
A WebSocket API in API Gateway is a collection of WebSocket routes that are integrated with backend HTTP endpoints, Lambda functions, or other AWS services. You can use API Gateway features to help you with all aspects of the API lifecycle, from creation through monitoring your production APIs. Read more
WebSocket APIs have two fundamental concepts - Routes and Integrations.
WebSocket APIs direct JSON messages to backend integrations based on configured routes. (Non-JSON messages are directed
to the configured $default route.)
Integrations define how the WebSocket API behaves when a client reaches a specific Route. Learn more at Configuring integrations.
Integrations are available in the aws-apigatewayv2-integrations module and more information is available in that module.
To add the default WebSocket routes supported by API Gateway ($connect, $disconnect and $default), configure them as part of api props:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object webSocketApi = WebSocketApi.Builder.create(stack, "mywsapi")
.connectRouteOptions(Map.of("integration", LambdaWebSocketIntegration.Builder.create().handler(connectHandler).build()))
.disconnectRouteOptions(Map.of("integration", LambdaWebSocketIntegration.Builder.create().handler(disconnetHandler).build()))
.defaultRouteOptions(Map.of("integration", LambdaWebSocketIntegration.Builder.create().handler(defaultHandler).build()))
.build();
WebSocketStage.Builder.create(stack, "mystage")
.webSocketApi(webSocketApi)
.stageName("dev")
.autoDeploy(true)
.build();
To add any other route:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object webSocketApi = new WebSocketApi(stack, "mywsapi");
webSocketApi.addRoute("sendmessage", Map.of(
"integration", LambdaWebSocketIntegration.Builder.create()
.handler(messageHandler)
.build()));
Copyright © 2021. All rights reserved.