awscdkawsapigatewayv2integrationsalpha

package module
v2.0.0-...-7bcaddb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

AWS APIGatewayv2 Integrations


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.

const booksFn = new lambda.Function(stack, 'BooksDefaultFn', { ... });
const booksIntegration = new LambdaProxyIntegration({
  handler: booksDefaultFn,
});

const httpApi = new HttpApi(stack, 'HttpApi');

httpApi.addRoutes({
  path: '/books',
  methods: [ HttpMethod.GET ],
  integration: booksIntegration,
});
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.

const booksIntegration = new HttpProxyIntegration({
  url: 'https://get-books-proxy.myproxy.internal',
});

const httpApi = new HttpApi(stack, 'HttpApi');

httpApi.addRoutes({
  path: '/books',
  methods: [ HttpMethod.GET ],
  integration: booksIntegration,
});
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:

const vpc = new ec2.Vpc(stack, 'VPC');
const lb = new elbv2.ALB(stack, 'lb', { vpc });
const listener = lb.addListener('listener', { port: 80 });
listener.addTargets('target', {
  port: 80,
});

const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
  defaultIntegration: new HttpAlbIntegration({
    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:

const vpc = new ec2.Vpc(stack, 'VPC');
const lb = new elbv2.NLB(stack, 'lb', { vpc });
const listener = lb.addListener('listener', { port: 80 });
listener.addTargets('target', {
  port: 80,
});

const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
  defaultIntegration: new HttpNlbIntegration({
    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:

const vpc = new ec2.Vpc(stack, 'VPC');
const vpcLink = new VpcLink(stack, 'VpcLink', { vpc });
const namespace = new servicediscovery.PrivateDnsNamespace(stack, 'Namespace', {
  name: 'boobar.com',
  vpc,
});
const service = namespace.createService('Service');

const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
  defaultIntegration: new HttpServiceDiscoveryIntegration({
    vpcLink,
    service,
  }),
});
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.

The following example creates a new header - header2 - as a copy of header1 and removes header1.

const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
  defaultIntegration: new HttpAlbIntegration({
    // ...
    requestParameters: new ParameterMapping()
      .appendHeader('header2', MappingValue.header('header1'))
      .removeHeader('header1');
    }),
  }),
});

To add mapping keys and values not yet supported by the CDK, use the custom() method:

const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
  defaultIntegration: new HttpAlbIntegration({
    listener,
    requestParameters: new 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

const webSocketApi = new WebSocketApi(stack, 'mywsapi');
new WebSocketStage(stack, 'mystage', {
  webSocketApi,
  stageName: 'dev',
  autoDeploy: true,
});

const messageHandler = new lambda.Function(stack, 'MessageHandler', {...});
webSocketApi.addRoute('sendmessage', {
  integration: new LambdaWebSocketIntegration({
    handler: connectHandler,
  }),
});

Documentation

Overview

Integrations for AWS APIGateway V2

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHttpAlbIntegration_Override

func NewHttpAlbIntegration_Override(h HttpAlbIntegration, props *HttpAlbIntegrationProps)

Experimental.

func NewHttpNlbIntegration_Override

func NewHttpNlbIntegration_Override(h HttpNlbIntegration, props *HttpNlbIntegrationProps)

Experimental.

func NewHttpProxyIntegration_Override

func NewHttpProxyIntegration_Override(h HttpProxyIntegration, props *HttpProxyIntegrationProps)

Experimental.

func NewHttpServiceDiscoveryIntegration_Override

func NewHttpServiceDiscoveryIntegration_Override(h HttpServiceDiscoveryIntegration, props *HttpServiceDiscoveryIntegrationProps)

Experimental.

func NewLambdaProxyIntegration_Override

func NewLambdaProxyIntegration_Override(l LambdaProxyIntegration, props *LambdaProxyIntegrationProps)

Experimental.

func NewLambdaWebSocketIntegration_Override

func NewLambdaWebSocketIntegration_Override(l LambdaWebSocketIntegration, props *LambdaWebSocketIntegrationProps)

Experimental.

Types

type HttpAlbIntegration

type HttpAlbIntegration interface {
	awscdkawsapigatewayv2alpha.IHttpRouteIntegration
	ConnectionType() awscdkawsapigatewayv2alpha.HttpConnectionType
	SetConnectionType(val awscdkawsapigatewayv2alpha.HttpConnectionType)
	HttpMethod() awscdkawsapigatewayv2alpha.HttpMethod
	SetHttpMethod(val awscdkawsapigatewayv2alpha.HttpMethod)
	IntegrationType() awscdkawsapigatewayv2alpha.HttpIntegrationType
	SetIntegrationType(val awscdkawsapigatewayv2alpha.HttpIntegrationType)
	PayloadFormatVersion() awscdkawsapigatewayv2alpha.PayloadFormatVersion
	SetPayloadFormatVersion(val awscdkawsapigatewayv2alpha.PayloadFormatVersion)
	Bind(options *awscdkawsapigatewayv2alpha.HttpRouteIntegrationBindOptions) *awscdkawsapigatewayv2alpha.HttpRouteIntegrationConfig
}

The Application Load Balancer integration resource for HTTP API. Experimental.

func NewHttpAlbIntegration

func NewHttpAlbIntegration(props *HttpAlbIntegrationProps) HttpAlbIntegration

Experimental.

type HttpAlbIntegrationProps

type HttpAlbIntegrationProps struct {
	// The HTTP method that must be used to invoke the underlying HTTP proxy.
	// Experimental.
	Method awscdkawsapigatewayv2alpha.HttpMethod `json:"method"`
	// Specifies how to transform HTTP requests before sending them to the backend.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html
	//
	// Experimental.
	ParameterMapping awscdkawsapigatewayv2alpha.ParameterMapping `json:"parameterMapping"`
	// Specifies the server name to verified by HTTPS when calling the backend integration.
	// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-integration-tlsconfig.html
	//
	// Experimental.
	SecureServerName *string `json:"secureServerName"`
	// The vpc link to be used for the private integration.
	// Experimental.
	VpcLink awscdkawsapigatewayv2alpha.IVpcLink `json:"vpcLink"`
	// The listener to the application load balancer used for the integration.
	// Experimental.
	Listener awselasticloadbalancingv2.IApplicationListener `json:"listener"`
}

Properties to initialize `HttpAlbIntegration`. Experimental.

type HttpNlbIntegration

type HttpNlbIntegration interface {
	awscdkawsapigatewayv2alpha.IHttpRouteIntegration
	ConnectionType() awscdkawsapigatewayv2alpha.HttpConnectionType
	SetConnectionType(val awscdkawsapigatewayv2alpha.HttpConnectionType)
	HttpMethod() awscdkawsapigatewayv2alpha.HttpMethod
	SetHttpMethod(val awscdkawsapigatewayv2alpha.HttpMethod)
	IntegrationType() awscdkawsapigatewayv2alpha.HttpIntegrationType
	SetIntegrationType(val awscdkawsapigatewayv2alpha.HttpIntegrationType)
	PayloadFormatVersion() awscdkawsapigatewayv2alpha.PayloadFormatVersion
	SetPayloadFormatVersion(val awscdkawsapigatewayv2alpha.PayloadFormatVersion)
	Bind(options *awscdkawsapigatewayv2alpha.HttpRouteIntegrationBindOptions) *awscdkawsapigatewayv2alpha.HttpRouteIntegrationConfig
}

The Network Load Balancer integration resource for HTTP API. Experimental.

func NewHttpNlbIntegration

func NewHttpNlbIntegration(props *HttpNlbIntegrationProps) HttpNlbIntegration

Experimental.

type HttpNlbIntegrationProps

type HttpNlbIntegrationProps struct {
	// The HTTP method that must be used to invoke the underlying HTTP proxy.
	// Experimental.
	Method awscdkawsapigatewayv2alpha.HttpMethod `json:"method"`
	// Specifies how to transform HTTP requests before sending them to the backend.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html
	//
	// Experimental.
	ParameterMapping awscdkawsapigatewayv2alpha.ParameterMapping `json:"parameterMapping"`
	// Specifies the server name to verified by HTTPS when calling the backend integration.
	// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-integration-tlsconfig.html
	//
	// Experimental.
	SecureServerName *string `json:"secureServerName"`
	// The vpc link to be used for the private integration.
	// Experimental.
	VpcLink awscdkawsapigatewayv2alpha.IVpcLink `json:"vpcLink"`
	// The listener to the network load balancer used for the integration.
	// Experimental.
	Listener awselasticloadbalancingv2.INetworkListener `json:"listener"`
}

Properties to initialize `HttpNlbIntegration`. Experimental.

type HttpPrivateIntegrationOptions

type HttpPrivateIntegrationOptions struct {
	// The HTTP method that must be used to invoke the underlying HTTP proxy.
	// Experimental.
	Method awscdkawsapigatewayv2alpha.HttpMethod `json:"method"`
	// Specifies how to transform HTTP requests before sending them to the backend.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html
	//
	// Experimental.
	ParameterMapping awscdkawsapigatewayv2alpha.ParameterMapping `json:"parameterMapping"`
	// Specifies the server name to verified by HTTPS when calling the backend integration.
	// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-integration-tlsconfig.html
	//
	// Experimental.
	SecureServerName *string `json:"secureServerName"`
	// The vpc link to be used for the private integration.
	// Experimental.
	VpcLink awscdkawsapigatewayv2alpha.IVpcLink `json:"vpcLink"`
}

Base options for private integration. Experimental.

type HttpProxyIntegration

type HttpProxyIntegration interface {
	awscdkawsapigatewayv2alpha.IHttpRouteIntegration
	Bind(_arg *awscdkawsapigatewayv2alpha.HttpRouteIntegrationBindOptions) *awscdkawsapigatewayv2alpha.HttpRouteIntegrationConfig
}

The HTTP Proxy integration resource for HTTP API. Experimental.

func NewHttpProxyIntegration

func NewHttpProxyIntegration(props *HttpProxyIntegrationProps) HttpProxyIntegration

Experimental.

type HttpProxyIntegrationProps

type HttpProxyIntegrationProps struct {
	// The full-qualified HTTP URL for the HTTP integration.
	// Experimental.
	Url *string `json:"url"`
	// The HTTP method that must be used to invoke the underlying HTTP proxy.
	// Experimental.
	Method awscdkawsapigatewayv2alpha.HttpMethod `json:"method"`
	// Specifies how to transform HTTP requests before sending them to the backend.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html
	//
	// Experimental.
	ParameterMapping awscdkawsapigatewayv2alpha.ParameterMapping `json:"parameterMapping"`
}

Properties to initialize a new `HttpProxyIntegration`. Experimental.

type HttpServiceDiscoveryIntegration

type HttpServiceDiscoveryIntegration interface {
	awscdkawsapigatewayv2alpha.IHttpRouteIntegration
	ConnectionType() awscdkawsapigatewayv2alpha.HttpConnectionType
	SetConnectionType(val awscdkawsapigatewayv2alpha.HttpConnectionType)
	HttpMethod() awscdkawsapigatewayv2alpha.HttpMethod
	SetHttpMethod(val awscdkawsapigatewayv2alpha.HttpMethod)
	IntegrationType() awscdkawsapigatewayv2alpha.HttpIntegrationType
	SetIntegrationType(val awscdkawsapigatewayv2alpha.HttpIntegrationType)
	PayloadFormatVersion() awscdkawsapigatewayv2alpha.PayloadFormatVersion
	SetPayloadFormatVersion(val awscdkawsapigatewayv2alpha.PayloadFormatVersion)
	Bind(_arg *awscdkawsapigatewayv2alpha.HttpRouteIntegrationBindOptions) *awscdkawsapigatewayv2alpha.HttpRouteIntegrationConfig
}

The Service Discovery integration resource for HTTP API. Experimental.

func NewHttpServiceDiscoveryIntegration

func NewHttpServiceDiscoveryIntegration(props *HttpServiceDiscoveryIntegrationProps) HttpServiceDiscoveryIntegration

Experimental.

type HttpServiceDiscoveryIntegrationProps

type HttpServiceDiscoveryIntegrationProps struct {
	// The HTTP method that must be used to invoke the underlying HTTP proxy.
	// Experimental.
	Method awscdkawsapigatewayv2alpha.HttpMethod `json:"method"`
	// Specifies how to transform HTTP requests before sending them to the backend.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html
	//
	// Experimental.
	ParameterMapping awscdkawsapigatewayv2alpha.ParameterMapping `json:"parameterMapping"`
	// Specifies the server name to verified by HTTPS when calling the backend integration.
	// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-integration-tlsconfig.html
	//
	// Experimental.
	SecureServerName *string `json:"secureServerName"`
	// The vpc link to be used for the private integration.
	// Experimental.
	VpcLink awscdkawsapigatewayv2alpha.IVpcLink `json:"vpcLink"`
	// The discovery service used for the integration.
	// Experimental.
	Service awsservicediscovery.IService `json:"service"`
}

Properties to initialize `HttpServiceDiscoveryIntegration`. Experimental.

type LambdaProxyIntegration

type LambdaProxyIntegration interface {
	awscdkawsapigatewayv2alpha.IHttpRouteIntegration
	Bind(options *awscdkawsapigatewayv2alpha.HttpRouteIntegrationBindOptions) *awscdkawsapigatewayv2alpha.HttpRouteIntegrationConfig
}

The Lambda Proxy integration resource for HTTP API. Experimental.

func NewLambdaProxyIntegration

func NewLambdaProxyIntegration(props *LambdaProxyIntegrationProps) LambdaProxyIntegration

Experimental.

type LambdaProxyIntegrationProps

type LambdaProxyIntegrationProps struct {
	// The handler for this integration.
	// Experimental.
	Handler awslambda.IFunction `json:"handler"`
	// Specifies how to transform HTTP requests before sending them to the backend.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-parameter-mapping.html
	//
	// Experimental.
	ParameterMapping awscdkawsapigatewayv2alpha.ParameterMapping `json:"parameterMapping"`
	// Version of the payload sent to the lambda handler.
	// See: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
	//
	// Experimental.
	PayloadFormatVersion awscdkawsapigatewayv2alpha.PayloadFormatVersion `json:"payloadFormatVersion"`
}

Lambda Proxy integration properties. Experimental.

type LambdaWebSocketIntegration

type LambdaWebSocketIntegration interface {
	awscdkawsapigatewayv2alpha.IWebSocketRouteIntegration
	Bind(options *awscdkawsapigatewayv2alpha.WebSocketRouteIntegrationBindOptions) *awscdkawsapigatewayv2alpha.WebSocketRouteIntegrationConfig
}

Lambda WebSocket Integration. Experimental.

func NewLambdaWebSocketIntegration

func NewLambdaWebSocketIntegration(props *LambdaWebSocketIntegrationProps) LambdaWebSocketIntegration

Experimental.

type LambdaWebSocketIntegrationProps

type LambdaWebSocketIntegrationProps struct {
	// The handler for this integration.
	// Experimental.
	Handler awslambda.IFunction `json:"handler"`
}

Lambda WebSocket Integration props. Experimental.

Directories

Path Synopsis
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.
Package jsii contains the functionaility needed for jsii packages to initialize their dependencies and themselves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL