Skip to main content

Integrations for AWS APIGateway V2

Project description

AWS APIGatewayv2 Integrations

---

cdk-constructs: Experimental

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 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.


Table of Contents

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.

The following code configures a route GET /books with a Lambda proxy integration.

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
books_fn = lambda_.Function(stack, "BooksDefaultFn", ...)
books_integration = LambdaProxyIntegration(
    handler=books_default_fn
)

http_api = HttpApi(stack, "HttpApi")

http_api.add_routes(
    path="/books",
    methods=[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.

The following code configures a route GET /books with an HTTP proxy integration to an HTTP endpoint get-books-proxy.myproxy.internal.

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
books_integration = HttpProxyIntegration(
    url="https://get-books-proxy.myproxy.internal"
)

http_api = HttpApi(stack, "HttpApi")

http_api.add_routes(
    path="/books",
    methods=[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:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
vpc = ec2.Vpc(stack, "VPC")
lb = elbv2.ALB(stack, "lb", vpc=vpc)
listener = lb.add_listener("listener", port=80)
listener.add_targets("target",
    port=80
)

http_endpoint = HttpApi(stack, "HttpProxyPrivateApi",
    default_integration=HttpAlbIntegration(
        listener=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:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
vpc = ec2.Vpc(stack, "VPC")
lb = elbv2.NLB(stack, "lb", vpc=vpc)
listener = lb.add_listener("listener", port=80)
listener.add_targets("target",
    port=80
)

http_endpoint = HttpApi(stack, "HttpProxyPrivateApi",
    default_integration=HttpNlbIntegration(
        listener=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:

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
vpc = ec2.Vpc(stack, "VPC")
vpc_link = VpcLink(stack, "VpcLink", vpc=vpc)
namespace = servicediscovery.PrivateDnsNamespace(stack, "Namespace",
    name="boobar.com",
    vpc=vpc
)
service = namespace.create_service("Service")

http_endpoint = HttpApi(stack, "HttpProxyPrivateApi",
    default_integration=HttpServiceDiscoveryIntegration(
        vpc_link=vpc_link,
        service=service
    )
)

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

# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
web_socket_api = WebSocketApi(stack, "mywsapi")
WebSocketStage(stack, "mystage",
    web_socket_api=web_socket_api,
    stage_name="dev",
    auto_deploy=True
)

message_handler = lambda_.Function(stack, "MessageHandler", ...)
web_socket_api.add_route("sendmessage",
    integration=LambdaWebSocketIntegration(
        handler=connect_handler
    )
)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file aws-cdk.aws-apigatewayv2-integrations-1.121.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-apigatewayv2-integrations-1.121.0.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-apigatewayv2-integrations-1.121.0.tar.gz
Algorithm Hash digest
SHA256 02e69fea1c52d90f3cdbe77f18c94b60baf6a7c7d0ccedfbae2becb7ee2e3548
MD5 62ca679f75cd5e798806462294ccea15
BLAKE2b-256 e1c3d0efe0d57591b63c69f5c2ddf5e8bea4ffaa4a7f8cc9d1d8a94c25d7f5f2

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_apigatewayv2_integrations-1.121.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_cdk.aws_apigatewayv2_integrations-1.121.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5815cb63416e16dd09ff5f5c8b04d398d7df8f93abd00d26504fd77f6989aab6
MD5 5347a88b9a3d6855366fae9d37fd26f2
BLAKE2b-256 01eed8eb240ade92d3fa01665a1757310e3df8b09e1b1504c3388437ad4c9a98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page