diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md b/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md index 2cda8eab308ab..5aa7f03dc3c26 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/README.md @@ -11,16 +11,66 @@ ## Table of Contents -- [Introduction](#introduction) -- [Private Integration](#private-integration) +- [HTTP APIs](#http-apis) + - [Lambda Integration](#lambda) + - [HTTP Proxy Integration](#http-proxy) + - [Private Integration](#private-integration) -## Introduction +## 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. -Currently the following integrations are supported by this construct library. +### Lambda -## Private Integration +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. + +```ts +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](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`. + +```ts +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 @@ -28,7 +78,7 @@ clients outside of the VPC. The following integrations are supported for private resources in a VPC. -### Application Load Balancer +#### Application Load Balancer The following code is a basic application load balancer private integration of HTTP API: @@ -47,7 +97,7 @@ const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', { }); ``` -### Network Load Balancer +#### Network Load Balancer The following code is a basic network load balancer private integration of HTTP API: @@ -66,7 +116,7 @@ const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', { }); ``` -### Cloud Map Service Discovery +#### Cloud Map Service Discovery The following code is a basic discovery service private integration of HTTP API: diff --git a/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/http.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/http-proxy.ts similarity index 81% rename from packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/http.ts rename to packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/http-proxy.ts index d5020d2d908ba..a7ef2d1b4d7b9 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/http.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/http-proxy.ts @@ -1,5 +1,11 @@ -import { HttpIntegrationType, HttpRouteIntegrationBindOptions, HttpRouteIntegrationConfig, IHttpRouteIntegration, PayloadFormatVersion } from '../integration'; -import { HttpMethod } from '../route'; +import { + HttpIntegrationType, + HttpRouteIntegrationBindOptions, + HttpRouteIntegrationConfig, + HttpMethod, + IHttpRouteIntegration, + PayloadFormatVersion, +} from '@aws-cdk/aws-apigatewayv2'; /** * Properties to initialize a new `HttpProxyIntegration`. diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/index.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/index.ts index bd4bb0ee34cac..8e0598975f8cb 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/index.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/index.ts @@ -2,3 +2,5 @@ export * from './base-types'; export * from './alb'; export * from './nlb'; export * from './service-discovery'; +export * from './http-proxy'; +export * from './lambda'; diff --git a/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/lambda.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/lambda.ts similarity index 89% rename from packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/lambda.ts rename to packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/lambda.ts index 9f0d4f89ee6f6..a962b268d7165 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/lambda.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/lib/http/lambda.ts @@ -1,7 +1,13 @@ +import { + HttpIntegrationType, + HttpRouteIntegrationBindOptions, + HttpRouteIntegrationConfig, + IHttpRouteIntegration, + PayloadFormatVersion, +} from '@aws-cdk/aws-apigatewayv2'; import { ServicePrincipal } from '@aws-cdk/aws-iam'; import { IFunction } from '@aws-cdk/aws-lambda'; import { Names, Stack } from '@aws-cdk/core'; -import { HttpIntegrationType, HttpRouteIntegrationBindOptions, HttpRouteIntegrationConfig, IHttpRouteIntegration, PayloadFormatVersion } from '../integration'; /** * Lambda Proxy integration properties diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json b/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json index 3cca63ba579e2..b233b0db9d9a1 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/package.json @@ -81,6 +81,8 @@ "@aws-cdk/aws-apigatewayv2": "0.0.0", "@aws-cdk/aws-ec2": "0.0.0", "@aws-cdk/aws-elasticloadbalancingv2": "0.0.0", + "@aws-cdk/aws-iam": "0.0.0", + "@aws-cdk/aws-lambda": "0.0.0", "@aws-cdk/aws-servicediscovery": "0.0.0", "@aws-cdk/core": "0.0.0", "constructs": "^3.2.0" @@ -89,6 +91,8 @@ "@aws-cdk/aws-apigatewayv2": "0.0.0", "@aws-cdk/aws-ec2": "0.0.0", "@aws-cdk/aws-elasticloadbalancingv2": "0.0.0", + "@aws-cdk/aws-iam": "0.0.0", + "@aws-cdk/aws-lambda": "0.0.0", "@aws-cdk/aws-servicediscovery": "0.0.0", "@aws-cdk/core": "0.0.0", "constructs": "^3.2.0" diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/http.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/http-proxy.test.ts similarity index 94% rename from packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/http.test.ts rename to packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/http-proxy.test.ts index c8d30e292b46c..8a0eb5830a7f4 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/http.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/http-proxy.test.ts @@ -1,6 +1,7 @@ import '@aws-cdk/assert/jest'; +import { HttpApi, HttpIntegration, HttpIntegrationType, HttpMethod, HttpRoute, HttpRouteKey, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2'; import { Stack } from '@aws-cdk/core'; -import { HttpApi, HttpIntegration, HttpIntegrationType, HttpMethod, HttpProxyIntegration, HttpRoute, HttpRouteKey, PayloadFormatVersion } from '../../../lib'; +import { HttpProxyIntegration } from '../../lib'; describe('HttpProxyIntegration', () => { test('default', () => { diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.http-proxy.expected.json b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.http-proxy.expected.json similarity index 100% rename from packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.http-proxy.expected.json rename to packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.http-proxy.expected.json diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.http-proxy.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.http-proxy.ts similarity index 89% rename from packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.http-proxy.ts rename to packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.http-proxy.ts index 15db80661e3f1..9fa5803973376 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.http-proxy.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.http-proxy.ts @@ -1,6 +1,7 @@ +import { HttpApi } from '@aws-cdk/aws-apigatewayv2'; import * as lambda from '@aws-cdk/aws-lambda'; import { App, CfnOutput, Stack } from '@aws-cdk/core'; -import { HttpApi, HttpProxyIntegration, LambdaProxyIntegration } from '../../../lib'; +import { HttpProxyIntegration, LambdaProxyIntegration } from '../../lib'; /* * Stack verification steps: diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.lambda-proxy.expected.json b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.lambda-proxy.expected.json similarity index 100% rename from packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.lambda-proxy.expected.json rename to packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.lambda-proxy.expected.json diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.lambda-proxy.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.lambda-proxy.ts similarity index 87% rename from packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.lambda-proxy.ts rename to packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.lambda-proxy.ts index 2114f94729edf..ed1cabee002e4 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/integ.lambda-proxy.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/integ.lambda-proxy.ts @@ -1,6 +1,7 @@ +import { HttpApi } from '@aws-cdk/aws-apigatewayv2'; import * as lambda from '@aws-cdk/aws-lambda'; import { App, CfnOutput, Stack } from '@aws-cdk/core'; -import { HttpApi, LambdaProxyIntegration } from '../../../lib'; +import { LambdaProxyIntegration } from '../../lib'; /* * Stack verification steps: diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/lambda.test.ts similarity index 92% rename from packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/lambda.test.ts rename to packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/lambda.test.ts index 8cdea2a3748c5..6272095194db6 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/integrations/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations/test/http/lambda.test.ts @@ -1,7 +1,8 @@ import '@aws-cdk/assert/jest'; +import { HttpApi, HttpRoute, HttpRouteKey, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2'; import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; import { App, Stack } from '@aws-cdk/core'; -import { HttpApi, HttpRoute, HttpRouteKey, LambdaProxyIntegration, PayloadFormatVersion } from '../../../lib'; +import { LambdaProxyIntegration } from '../../lib'; describe('LambdaProxyIntegration', () => { test('default', () => { diff --git a/packages/@aws-cdk/aws-apigatewayv2/README.md b/packages/@aws-cdk/aws-apigatewayv2/README.md index c25027fc81c39..ea93eda2149ed 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/README.md +++ b/packages/@aws-cdk/aws-apigatewayv2/README.md @@ -52,14 +52,13 @@ path, such as, `GET /books`. Learn more at [Working with routes](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html). 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 two types of -integrations - Lambda proxy integration and HTTP proxy integration. Learn more at [Configuring -integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations.html). +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](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations.html). -The code snippet below configures a route `GET /books` with an HTTP proxy integration and uses the `ANY` method to -proxy all other HTTP method calls to `/books` to a lambda proxy. - -The URL to the endpoint can be retrieved via the `apiEndpoint` attribute. +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. ```ts const getBooksIntegration = new HttpProxyIntegration({ @@ -85,6 +84,8 @@ httpApi.addRoutes({ }); ``` +The URL to the endpoint can be retrieved via the `apiEndpoint` attribute. + 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. diff --git a/packages/@aws-cdk/aws-apigatewayv2/lib/http/index.ts b/packages/@aws-cdk/aws-apigatewayv2/lib/http/index.ts index ee07bd7af8ee2..c594da33bac91 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/lib/http/index.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/lib/http/index.ts @@ -1,7 +1,6 @@ export * from './api'; export * from './route'; export * from './integration'; -export * from './integrations'; export * from './stage'; export * from './api-mapping'; export * from './vpc-link'; diff --git a/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/index.ts b/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/index.ts deleted file mode 100644 index 7797fe6ea8b03..0000000000000 --- a/packages/@aws-cdk/aws-apigatewayv2/lib/http/integrations/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './http'; -export * from './lambda'; \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigatewayv2/package.json b/packages/@aws-cdk/aws-apigatewayv2/package.json index 07b768f848bdd..126cbc4143d00 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/package.json +++ b/packages/@aws-cdk/aws-apigatewayv2/package.json @@ -83,7 +83,6 @@ "@aws-cdk/aws-certificatemanager": "0.0.0", "@aws-cdk/aws-ec2": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", - "@aws-cdk/aws-lambda": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/core": "0.0.0", "constructs": "^3.2.0" @@ -91,7 +90,6 @@ "peerDependencies": { "@aws-cdk/aws-ec2": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", - "@aws-cdk/aws-lambda": "0.0.0", "@aws-cdk/aws-certificatemanager": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/core": "0.0.0", diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts b/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts index 96c747985be04..fb91ec588be56 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts @@ -2,9 +2,8 @@ import '@aws-cdk/assert/jest'; import { ABSENT } from '@aws-cdk/assert'; import { Metric } from '@aws-cdk/aws-cloudwatch'; import * as ec2 from '@aws-cdk/aws-ec2'; -import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; import { Duration, Stack } from '@aws-cdk/core'; -import { HttpApi, HttpMethod, LambdaProxyIntegration } from '../../lib'; +import { HttpApi, HttpIntegrationType, HttpMethod, HttpRouteIntegrationBindOptions, HttpRouteIntegrationConfig, IHttpRouteIntegration, PayloadFormatVersion } from '../../lib'; describe('HttpApi', () => { test('default', () => { @@ -50,13 +49,7 @@ describe('HttpApi', () => { test('default integration', () => { const stack = new Stack(); const httpApi = new HttpApi(stack, 'api', { - defaultIntegration: new LambdaProxyIntegration({ - handler: new Function(stack, 'fn', { - code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_12_X, - handler: 'index.handler', - }), - }), + defaultIntegration: new DummyRouteIntegration(), }); expect(stack).toHaveResourceLike('AWS::ApiGatewayV2::Route', { @@ -76,13 +69,7 @@ describe('HttpApi', () => { httpApi.addRoutes({ path: '/pets', methods: [HttpMethod.GET, HttpMethod.PATCH], - integration: new LambdaProxyIntegration({ - handler: new Function(stack, 'fn', { - code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_12_X, - handler: 'index.handler', - }), - }), + integration: new DummyRouteIntegration(), }); expect(stack).toHaveResourceLike('AWS::ApiGatewayV2::Route', { @@ -102,13 +89,7 @@ describe('HttpApi', () => { httpApi.addRoutes({ path: '/pets', - integration: new LambdaProxyIntegration({ - handler: new Function(stack, 'fn', { - code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_12_X, - handler: 'index.handler', - }), - }), + integration: new DummyRouteIntegration(), }); expect(stack).toHaveResourceLike('AWS::ApiGatewayV2::Route', { @@ -281,3 +262,13 @@ describe('HttpApi', () => { expect(api.apiEndpoint).toBeDefined(); }); }); + +class DummyRouteIntegration implements IHttpRouteIntegration { + public bind(_: HttpRouteIntegrationBindOptions): HttpRouteIntegrationConfig { + return { + payloadFormatVersion: PayloadFormatVersion.VERSION_2_0, + type: HttpIntegrationType.HTTP_PROXY, + uri: 'some-uri', + }; + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integ.custom-domain.expected.json b/packages/@aws-cdk/aws-apigatewayv2/test/http/integ.custom-domain.expected.json deleted file mode 100644 index 2273bb18b02b4..0000000000000 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/integ.custom-domain.expected.json +++ /dev/null @@ -1,335 +0,0 @@ -{ - "Resources": { - "echohandlerServiceRole833A8F7A": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - } - ], - "Version": "2012-10-17" - }, - "ManagedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - ] - } - ] - } - }, - "echohandler8F648AB2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async function(event, context) { return { statusCode: 200, headers: { \"content-type\": \"application/json\" }, body: JSON.stringify(event) }; };" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "echohandlerServiceRole833A8F7A", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "DependsOn": [ - "echohandlerServiceRole833A8F7A" - ] - }, - "DNFDC76583": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "apigv2.demo.com", - "DomainNameConfigurations": [ - { - "CertificateArn": "arn:aws:acm:us-east-1:111111111111:certificate", - "EndpointType": "REGIONAL" - } - ] - } - }, - "HttpProxyProdApi368B6161": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Name": "HttpProxyProdApi", - "ProtocolType": "HTTP" - } - }, - "HttpProxyProdApiDefaultRouteinteghttpproxyHttpProxyProdApiDefaultRoute20082F68PermissionB29E0EB7": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "echohandler8F648AB2", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "HttpProxyProdApi368B6161" - }, - "/*/*" - ] - ] - } - } - }, - "HttpProxyProdApiDefaultRouteDefaultRouteIntegration702F0DF7": { - "Type": "AWS::ApiGatewayV2::Integration", - "Properties": { - "ApiId": { - "Ref": "HttpProxyProdApi368B6161" - }, - "IntegrationType": "AWS_PROXY", - "IntegrationUri": { - "Fn::GetAtt": [ - "echohandler8F648AB2", - "Arn" - ] - }, - "PayloadFormatVersion": "2.0" - } - }, - "HttpProxyProdApiDefaultRoute40EFC108": { - "Type": "AWS::ApiGatewayV2::Route", - "Properties": { - "ApiId": { - "Ref": "HttpProxyProdApi368B6161" - }, - "RouteKey": "$default", - "Target": { - "Fn::Join": [ - "", - [ - "integrations/", - { - "Ref": "HttpProxyProdApiDefaultRouteDefaultRouteIntegration702F0DF7" - } - ] - ] - } - } - }, - "HttpProxyProdApiDefaultStage0038B180": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HttpProxyProdApi368B6161" - }, - "StageName": "$default", - "AutoDeploy": true - }, - "DependsOn": [ - "DNFDC76583" - ] - }, - "HttpProxyProdApiDefaultStageinteghttpproxyDNfoo38514765": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "HttpProxyProdApi368B6161" - }, - "DomainName": "apigv2.demo.com", - "Stage": "$default", - "ApiMappingKey": "foo" - }, - "DependsOn": [ - "DNFDC76583", - "HttpProxyProdApiDefaultStage0038B180" - ] - }, - "HttpProxyProdApiBetaStage7074CBDF": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HttpProxyProdApi368B6161" - }, - "StageName": "beta", - "AutoDeploy": true - }, - "DependsOn": [ - "DNFDC76583" - ] - }, - "HttpProxyProdApiBetaStageinteghttpproxyDNbarA0E8C5B4": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "HttpProxyProdApi368B6161" - }, - "DomainName": "apigv2.demo.com", - "Stage": "beta", - "ApiMappingKey": "bar" - }, - "DependsOn": [ - "DNFDC76583", - "HttpProxyProdApiBetaStage7074CBDF" - ] - }, - "DemoApiE67238F8": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Name": "DemoApi", - "ProtocolType": "HTTP" - } - }, - "DemoApiDefaultRouteinteghttpproxyDemoApiDefaultRoute050CFFE6PermissionB1FE82E7": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "echohandler8F648AB2", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":execute-api:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":", - { - "Ref": "DemoApiE67238F8" - }, - "/*/*" - ] - ] - } - } - }, - "DemoApiDefaultRouteDefaultRouteIntegration714B9B03": { - "Type": "AWS::ApiGatewayV2::Integration", - "Properties": { - "ApiId": { - "Ref": "DemoApiE67238F8" - }, - "IntegrationType": "AWS_PROXY", - "IntegrationUri": { - "Fn::GetAtt": [ - "echohandler8F648AB2", - "Arn" - ] - }, - "PayloadFormatVersion": "2.0" - } - }, - "DemoApiDefaultRouteF8069A72": { - "Type": "AWS::ApiGatewayV2::Route", - "Properties": { - "ApiId": { - "Ref": "DemoApiE67238F8" - }, - "RouteKey": "$default", - "Target": { - "Fn::Join": [ - "", - [ - "integrations/", - { - "Ref": "DemoApiDefaultRouteDefaultRouteIntegration714B9B03" - } - ] - ] - } - } - }, - "DemoApiDefaultStage5FCE2787": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "DemoApiE67238F8" - }, - "StageName": "$default", - "AutoDeploy": true - }, - "DependsOn": [ - "DNFDC76583" - ] - }, - "DemoApiDefaultStageinteghttpproxyDNdemo045504F3": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "DemoApiE67238F8" - }, - "DomainName": "apigv2.demo.com", - "Stage": "$default", - "ApiMappingKey": "demo" - }, - "DependsOn": [ - "DemoApiDefaultStage5FCE2787", - "DNFDC76583" - ] - } - }, - "Outputs": { - "RegionalDomainName": { - "Value": { - "Fn::GetAtt": [ - "DNFDC76583", - "RegionalDomainName" - ] - } - }, - "DomainName": { - "Value": "apigv2.demo.com" - }, - "CustomUDomainURL": { - "Value": "https://apigv2.demo.com" - }, - "ProdApiDefaultStageURL": { - "Value": "https://apigv2.demo.com/foo" - }, - "ProdApiBetaStageURL": { - "Value": "https://apigv2.demo.com/bar" - }, - "DemoApiDefaultStageURL": { - "Value": "https://apigv2.demo.com/demo" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/integ.custom-domain.ts b/packages/@aws-cdk/aws-apigatewayv2/test/http/integ.custom-domain.ts deleted file mode 100644 index 0046b1a505e1c..0000000000000 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/integ.custom-domain.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as acm from '@aws-cdk/aws-certificatemanager'; -import * as lambda from '@aws-cdk/aws-lambda'; -import { App, CfnOutput, Stack } from '@aws-cdk/core'; -import { DomainName, HttpApi, LambdaProxyIntegration } from '../../lib'; - -const app = new App(); - -const stack = new Stack(app, 'integ-http-proxy'); - -const handler = new lambda.Function(stack, 'echohandler', { - runtime: lambda.Runtime.NODEJS_12_X, - handler: 'index.handler', - code: new lambda.InlineCode('exports.handler = async function(event, context) { return { statusCode: 200, headers: { "content-type": "application/json" }, body: JSON.stringify(event) }; };'), -}); - -const certArn = 'arn:aws:acm:us-east-1:111111111111:certificate'; -const domainName = 'apigv2.demo.com'; - -const dn = new DomainName(stack, 'DN', { - domainName, - certificate: acm.Certificate.fromCertificateArn(stack, 'cert', certArn), -}); - -const prodApi = new HttpApi(stack, 'HttpProxyProdApi', { - defaultIntegration: new LambdaProxyIntegration({ handler }), - // https://${dn.domainName}/foo goes to prodApi $default stage - defaultDomainMapping: { - domainName: dn, - mappingKey: 'foo', - }, -}); - -// beta stage -prodApi.addStage('BetaStage', { - stageName: 'beta', - autoDeploy: true, - // https://${dn.domainName}/bar goes to the beta stage - domainMapping: { - domainName: dn, - mappingKey: 'bar', - }, -}); - -// the Demo API -new HttpApi(stack, 'DemoApi', { - defaultIntegration: new LambdaProxyIntegration({ handler }), - // https://${dn.domainName}/demo goes to apiDemo $default stage - defaultDomainMapping: { - domainName: dn, - mappingKey: 'demo', - }, -}); - -new CfnOutput(stack, 'RegionalDomainName', { value: dn.regionalDomainName }); -new CfnOutput(stack, 'DomainName', { value: dn.domainName }); -new CfnOutput(stack, 'CustomUDomainURL', { value: `https://${dn.domainName}` }); -new CfnOutput(stack, 'ProdApiDefaultStageURL', { value: `https://${dn.domainName}/foo` }); -new CfnOutput(stack, 'ProdApiBetaStageURL', { value: `https://${dn.domainName}/bar` }); -new CfnOutput(stack, 'DemoApiDefaultStageURL', { value: `https://${dn.domainName}/demo` });