# AWS APIGatewayv2 Integrations
<!--BEGIN STABILITY BANNER-->---
![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
> The APIs of higher level constructs in this module are experimental and 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](https://semver.org/) 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.
---
<!--END STABILITY BANNER-->
## Table of Contents
* [HTTP APIs](#http-apis)
* [Lambda Integration](#lambda)
* [HTTP Proxy Integration](#http-proxy)
* [Private Integration](#private-integration)
* [Request Parameters](#request-parameters)
* [WebSocket APIs](#websocket-apis)
* [Lambda WebSocket Integration](#lambda-websocket-integration)
## HTTP APIs
Integrations connect a route to backend resources. HTTP APIs support Lambda proxy, AWS service, and HTTP proxy integrations. HTTP proxy integrations are also known as private integrations.
### Lambda
Lambda integrations enable integrating an HTTP API route with a Lambda function. When a client invokes the route, the
API Gateway service forwards the request to the Lambda function and returns the function's response to the client.
The API Gateway service will invoke the lambda function with an event payload of a specific format. The service expects
the function to respond in a specific format. The details on this format is available at [Working with AWS Lambda
proxy integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
The following code configures a route `GET /books` with a Lambda proxy integration.
```python
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
# books_default_fn: lambda.Function
books_integration = HttpLambdaIntegration("BooksIntegration", books_default_fn)
http_api = apigwv2.HttpApi(self, "HttpApi")
http_api.add_routes(
path="/books",
methods=[apigwv2.HttpMethod.GET],
integration=books_integration
)
```
### HTTP Proxy
HTTP Proxy integrations enables connecting an HTTP API route to a publicly routable HTTP endpoint. When a client
invokes the route, the API Gateway service forwards the entire request and response between the API Gateway endpoint
and the integrating HTTP endpoint. More information can be found at [Working with HTTP proxy
integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-http.html).
The following code configures a route `GET /books` with an HTTP proxy integration to an HTTP endpoint
`get-books-proxy.myproxy.internal`.
```python
from aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration
books_integration = HttpUrlIntegration("BooksIntegration", "https://get-books-proxy.myproxy.internal")
http_api = apigwv2.HttpApi(self, "HttpApi")
http_api.add_routes(
path="/books",
methods=[apigwv2.HttpMethod.GET],
integration=books_integration
)
```
### Private Integration
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.
The following integrations are supported for private resources in a VPC.
#### Application Load Balancer
The following code is a basic application load balancer private integration of HTTP API:
```python
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
vpc = ec2.Vpc(self, "VPC")
lb = elbv2.ApplicationLoadBalancer(self, "lb", vpc=vpc)
listener = lb.add_listener("listener", port=80)
listener.add_targets("target",
port=80
)
http_endpoint = apigwv2.HttpApi(self, "HttpProxyPrivateApi",
default_integration=HttpAlbIntegration("DefaultIntegration", listener)
)
```
When an imported load balancer is used, the `vpc` option must be specified for `HttpAlbIntegration`.
#### Network Load Balancer
The following code is a basic network load balancer private integration of HTTP API:
```python
from aws_cdk.aws_apigatewayv2_integrations import HttpNlbIntegration
vpc = ec2.Vpc(self, "VPC")
lb = elbv2.NetworkLoadBalancer(self, "lb", vpc=vpc)
listener = lb.add_listener("listener", port=80)
listener.add_targets("target",
port=80
)
http_endpoint = apigwv2.HttpApi(self, "HttpProxyPrivateApi",
default_integration=HttpNlbIntegration("DefaultIntegration", listener)
)
```
When an imported load balancer is used, the `vpc` option must be specified for `HttpNlbIntegration`.
#### Cloud Map Service Discovery
The following code is a basic discovery service private integration of HTTP API:
```python
import aws_cdk.aws_servicediscovery as servicediscovery
from aws_cdk.aws_apigatewayv2_integrations import HttpServiceDiscoveryIntegration
vpc = ec2.Vpc(self, "VPC")
vpc_link = apigwv2.VpcLink(self, "VpcLink", vpc=vpc)
namespace = servicediscovery.PrivateDnsNamespace(self, "Namespace",
name="boobar.com",
vpc=vpc
)
service = namespace.create_service("Service")
http_endpoint = apigwv2.HttpApi(self, "HttpProxyPrivateApi",
default_integration=HttpServiceDiscoveryIntegration("DefaultIntegration", service,
vpc_link=vpc_link
)
)
```
### Request Parameters
Request parameter mapping allows API requests from clients to be modified before they reach backend integrations.
Parameter mapping can be used to specify modifications to request parameters. See [Transforming API requests and
responses](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html).
The following example creates a new header - `header2` - as a copy of `header1` and removes `header1`.
```python
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
# lb: elbv2.ApplicationLoadBalancer
listener = lb.add_listener("listener", port=80)
listener.add_targets("target",
port=80
)
http_endpoint = apigwv2.HttpApi(self, "HttpProxyPrivateApi",
default_integration=HttpAlbIntegration("DefaultIntegration", listener,
parameter_mapping=apigwv2.ParameterMapping().append_header("header2", apigwv2.MappingValue.request_header("header1")).remove_header("header1")
)
)
```
To add mapping keys and values not yet supported by the CDK, use the `custom()` method:
```python
from aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration
# lb: elbv2.ApplicationLoadBalancer
listener = lb.add_listener("listener", port=80)
listener.add_targets("target",
port=80
)
http_endpoint = apigwv2.HttpApi(self, "HttpProxyPrivateApi",
default_integration=HttpAlbIntegration("DefaultIntegration", listener,
parameter_mapping=apigwv2.ParameterMapping().custom("myKey", "myValue")
)
)
```
## WebSocket APIs
WebSocket integrations connect a route to backend resources. The following integrations are supported in the CDK.
### Lambda WebSocket Integration
Lambda integrations enable integrating a WebSocket API route with a Lambda function. When a client connects/disconnects
or sends message specific to a route, the API Gateway service forwards the request to the Lambda function
The API Gateway service will invoke the lambda function with an event payload of a specific format.
The following code configures a `sendmessage` route with a Lambda integration
```python
from aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration
# message_handler: lambda.Function
web_socket_api = apigwv2.WebSocketApi(self, "mywsapi")
apigwv2.WebSocketStage(self, "mystage",
web_socket_api=web_socket_api,
stage_name="dev",
auto_deploy=True
)
web_socket_api.add_route("sendmessage",
integration=WebSocketLambdaIntegration("SendMessageIntegration", message_handler)
)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/aws/aws-cdk",
"name": "aws-cdk.aws-apigatewayv2-integrations",
"maintainer": "",
"docs_url": null,
"requires_python": "~=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Amazon Web Services",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/4b/6a/4b13ce4c364bd1e279f4ebe6505bf5b2f0f718c360032154d90a43725f7c/aws-cdk.aws-apigatewayv2-integrations-1.203.0.tar.gz",
"platform": null,
"description": "# AWS APIGatewayv2 Integrations\n\n<!--BEGIN STABILITY BANNER-->---\n\n\n![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)\n\n> The APIs of higher level constructs in this module are experimental and under active development.\n> They are subject to non-backward compatible changes or removal in any future version. These are\n> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be\n> announced in the release notes. This means that while you may use them, you may need to update\n> your source code when upgrading to a newer version of this package.\n\n---\n<!--END STABILITY BANNER-->\n\n## Table of Contents\n\n* [HTTP APIs](#http-apis)\n\n * [Lambda Integration](#lambda)\n * [HTTP Proxy Integration](#http-proxy)\n * [Private Integration](#private-integration)\n * [Request Parameters](#request-parameters)\n* [WebSocket APIs](#websocket-apis)\n\n * [Lambda WebSocket Integration](#lambda-websocket-integration)\n\n## HTTP APIs\n\nIntegrations connect a route to backend resources. HTTP APIs support Lambda proxy, AWS service, and HTTP proxy integrations. HTTP proxy integrations are also known as private integrations.\n\n### Lambda\n\nLambda integrations enable integrating an HTTP API route with a Lambda function. When a client invokes the route, the\nAPI Gateway service forwards the request to the Lambda function and returns the function's response to the client.\n\nThe API Gateway service will invoke the lambda function with an event payload of a specific format. The service expects\nthe function to respond in a specific format. The details on this format is available at [Working with AWS Lambda\nproxy integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).\n\nThe following code configures a route `GET /books` with a Lambda proxy integration.\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration\n\n# books_default_fn: lambda.Function\n\nbooks_integration = HttpLambdaIntegration(\"BooksIntegration\", books_default_fn)\n\nhttp_api = apigwv2.HttpApi(self, \"HttpApi\")\n\nhttp_api.add_routes(\n path=\"/books\",\n methods=[apigwv2.HttpMethod.GET],\n integration=books_integration\n)\n```\n\n### HTTP Proxy\n\nHTTP Proxy integrations enables connecting an HTTP API route to a publicly routable HTTP endpoint. When a client\ninvokes the route, the API Gateway service forwards the entire request and response between the API Gateway endpoint\nand the integrating HTTP endpoint. More information can be found at [Working with HTTP proxy\nintegrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-http.html).\n\nThe following code configures a route `GET /books` with an HTTP proxy integration to an HTTP endpoint\n`get-books-proxy.myproxy.internal`.\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration\n\n\nbooks_integration = HttpUrlIntegration(\"BooksIntegration\", \"https://get-books-proxy.myproxy.internal\")\n\nhttp_api = apigwv2.HttpApi(self, \"HttpApi\")\n\nhttp_api.add_routes(\n path=\"/books\",\n methods=[apigwv2.HttpMethod.GET],\n integration=books_integration\n)\n```\n\n### Private Integration\n\nPrivate integrations enable integrating an HTTP API route with private resources in a VPC, such as Application Load Balancers or\nAmazon ECS container-based applications. Using private integrations, resources in a VPC can be exposed for access by\nclients outside of the VPC.\n\nThe following integrations are supported for private resources in a VPC.\n\n#### Application Load Balancer\n\nThe following code is a basic application load balancer private integration of HTTP API:\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration\n\n\nvpc = ec2.Vpc(self, \"VPC\")\nlb = elbv2.ApplicationLoadBalancer(self, \"lb\", vpc=vpc)\nlistener = lb.add_listener(\"listener\", port=80)\nlistener.add_targets(\"target\",\n port=80\n)\n\nhttp_endpoint = apigwv2.HttpApi(self, \"HttpProxyPrivateApi\",\n default_integration=HttpAlbIntegration(\"DefaultIntegration\", listener)\n)\n```\n\nWhen an imported load balancer is used, the `vpc` option must be specified for `HttpAlbIntegration`.\n\n#### Network Load Balancer\n\nThe following code is a basic network load balancer private integration of HTTP API:\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpNlbIntegration\n\n\nvpc = ec2.Vpc(self, \"VPC\")\nlb = elbv2.NetworkLoadBalancer(self, \"lb\", vpc=vpc)\nlistener = lb.add_listener(\"listener\", port=80)\nlistener.add_targets(\"target\",\n port=80\n)\n\nhttp_endpoint = apigwv2.HttpApi(self, \"HttpProxyPrivateApi\",\n default_integration=HttpNlbIntegration(\"DefaultIntegration\", listener)\n)\n```\n\nWhen an imported load balancer is used, the `vpc` option must be specified for `HttpNlbIntegration`.\n\n#### Cloud Map Service Discovery\n\nThe following code is a basic discovery service private integration of HTTP API:\n\n```python\nimport aws_cdk.aws_servicediscovery as servicediscovery\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpServiceDiscoveryIntegration\n\n\nvpc = ec2.Vpc(self, \"VPC\")\nvpc_link = apigwv2.VpcLink(self, \"VpcLink\", vpc=vpc)\nnamespace = servicediscovery.PrivateDnsNamespace(self, \"Namespace\",\n name=\"boobar.com\",\n vpc=vpc\n)\nservice = namespace.create_service(\"Service\")\n\nhttp_endpoint = apigwv2.HttpApi(self, \"HttpProxyPrivateApi\",\n default_integration=HttpServiceDiscoveryIntegration(\"DefaultIntegration\", service,\n vpc_link=vpc_link\n )\n)\n```\n\n### Request Parameters\n\nRequest parameter mapping allows API requests from clients to be modified before they reach backend integrations.\nParameter mapping can be used to specify modifications to request parameters. See [Transforming API requests and\nresponses](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html).\n\nThe following example creates a new header - `header2` - as a copy of `header1` and removes `header1`.\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration\n\n# lb: elbv2.ApplicationLoadBalancer\n\nlistener = lb.add_listener(\"listener\", port=80)\nlistener.add_targets(\"target\",\n port=80\n)\n\nhttp_endpoint = apigwv2.HttpApi(self, \"HttpProxyPrivateApi\",\n default_integration=HttpAlbIntegration(\"DefaultIntegration\", listener,\n parameter_mapping=apigwv2.ParameterMapping().append_header(\"header2\", apigwv2.MappingValue.request_header(\"header1\")).remove_header(\"header1\")\n )\n)\n```\n\nTo add mapping keys and values not yet supported by the CDK, use the `custom()` method:\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import HttpAlbIntegration\n\n# lb: elbv2.ApplicationLoadBalancer\n\nlistener = lb.add_listener(\"listener\", port=80)\nlistener.add_targets(\"target\",\n port=80\n)\n\nhttp_endpoint = apigwv2.HttpApi(self, \"HttpProxyPrivateApi\",\n default_integration=HttpAlbIntegration(\"DefaultIntegration\", listener,\n parameter_mapping=apigwv2.ParameterMapping().custom(\"myKey\", \"myValue\")\n )\n)\n```\n\n## WebSocket APIs\n\nWebSocket integrations connect a route to backend resources. The following integrations are supported in the CDK.\n\n### Lambda WebSocket Integration\n\nLambda integrations enable integrating a WebSocket API route with a Lambda function. When a client connects/disconnects\nor sends message specific to a route, the API Gateway service forwards the request to the Lambda function\n\nThe API Gateway service will invoke the lambda function with an event payload of a specific format.\n\nThe following code configures a `sendmessage` route with a Lambda integration\n\n```python\nfrom aws_cdk.aws_apigatewayv2_integrations import WebSocketLambdaIntegration\n\n# message_handler: lambda.Function\n\n\nweb_socket_api = apigwv2.WebSocketApi(self, \"mywsapi\")\napigwv2.WebSocketStage(self, \"mystage\",\n web_socket_api=web_socket_api,\n stage_name=\"dev\",\n auto_deploy=True\n)\nweb_socket_api.add_route(\"sendmessage\",\n integration=WebSocketLambdaIntegration(\"SendMessageIntegration\", message_handler)\n)\n```\n\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Integrations for AWS APIGateway V2",
"version": "1.203.0",
"project_urls": {
"Homepage": "https://github.com/aws/aws-cdk",
"Source": "https://github.com/aws/aws-cdk.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8828fd208af3be0ff6c9cd79ecbb8f250a9a359cb33d5863afa14e19bdf75ed0",
"md5": "f2ff7cd298fac0ee500f47ede8d4e750",
"sha256": "3c3d8568c6e0a4b1e4bd3d72496350be0bd79634ea109ab701ad04317e777967"
},
"downloads": -1,
"filename": "aws_cdk.aws_apigatewayv2_integrations-1.203.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f2ff7cd298fac0ee500f47ede8d4e750",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.7",
"size": 57521,
"upload_time": "2023-05-31T22:52:33",
"upload_time_iso_8601": "2023-05-31T22:52:33.075292Z",
"url": "https://files.pythonhosted.org/packages/88/28/fd208af3be0ff6c9cd79ecbb8f250a9a359cb33d5863afa14e19bdf75ed0/aws_cdk.aws_apigatewayv2_integrations-1.203.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4b6a4b13ce4c364bd1e279f4ebe6505bf5b2f0f718c360032154d90a43725f7c",
"md5": "315dd340556dc9318b2dcff620c27420",
"sha256": "5fe010a3baee418a3c9e89e047366cbcf30a863e0434760e4e9b489e4546c345"
},
"downloads": -1,
"filename": "aws-cdk.aws-apigatewayv2-integrations-1.203.0.tar.gz",
"has_sig": false,
"md5_digest": "315dd340556dc9318b2dcff620c27420",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.7",
"size": 58369,
"upload_time": "2023-05-31T23:00:32",
"upload_time_iso_8601": "2023-05-31T23:00:32.806168Z",
"url": "https://files.pythonhosted.org/packages/4b/6a/4b13ce4c364bd1e279f4ebe6505bf5b2f0f718c360032154d90a43725f7c/aws-cdk.aws-apigatewayv2-integrations-1.203.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-31 23:00:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aws",
"github_project": "aws-cdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aws-cdk.aws-apigatewayv2-integrations"
}