Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(apigatewayv2): integration api re-organization #17752

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions packages/@aws-cdk/aws-apigatewayv2-authorizers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The example below showcases default authorization, along with route authorizatio

nija-at marked this conversation as resolved.
Show resolved Hide resolved
```ts
import { HttpJwtAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers';
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

const authorizer = new HttpJwtAuthorizer({
jwtAudience: ['3131231'],
Expand All @@ -84,34 +84,26 @@ const api = new apigwv2.HttpApi(this, 'HttpApi', {
});

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/books',
methods: [apigwv2.HttpMethod.GET],
});

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('BooksIdIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/books/{id}',
methods: [apigwv2.HttpMethod.GET],
});

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/books',
methods: [apigwv2.HttpMethod.POST],
authorizationScopes: ['write:books']
});

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('LoginIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/login',
methods: [apigwv2.HttpMethod.POST],
authorizer: new apigwv2.HttpNoneAuthorizer(),
Expand All @@ -136,7 +128,7 @@ Clients that fail authorization are presented with either 2 responses:

```ts
import { HttpJwtAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers';
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

const authorizer = new HttpJwtAuthorizer({
jwtAudience: ['3131231'],
Expand All @@ -146,9 +138,7 @@ const authorizer = new HttpJwtAuthorizer({
const api = new apigwv2.HttpApi(this, 'HttpApi');

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/books',
authorizer,
});
Expand All @@ -165,7 +155,7 @@ pools as authorizer](https://docs.aws.amazon.com/apigateway/latest/developerguid
```ts
import * as cognito from '@aws-cdk/aws-cognito';
import { HttpUserPoolAuthorizer } from '@aws-cdk/aws-apigatewayv2-authorizers';
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

const userPool = new cognito.UserPool(this, 'UserPool');
const userPoolClient = userPool.addClient('UserPoolClient');
Expand All @@ -178,9 +168,7 @@ const authorizer = new HttpUserPoolAuthorizer({
const api = new apigwv2.HttpApi(this, 'HttpApi');

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/books',
authorizer,
});
Expand All @@ -195,7 +183,7 @@ Lambda authorizers depending on their response, fall into either two types - Sim

```ts
import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '@aws-cdk/aws-apigatewayv2-authorizers';
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

// This function handles your auth logic
declare const authHandler: lambda.Function;
Expand All @@ -209,9 +197,7 @@ const authorizer = new HttpLambdaAuthorizer({
const api = new apigwv2.HttpApi(this, 'HttpApi');

api.addRoutes({
integration: new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
}),
integration: new HttpUrlIntegration('BooksIntegration', 'https://get-books-proxy.myproxy.internal'),
path: '/books',
authorizer,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"AutoDeploy": true
}
},
"MyHttpApiGETAuthorizerIntegMyHttpApiGET16D02385PermissionBB02EBFE": {
"MyHttpApiGETRootIntegrationPermission81613491": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
Expand Down Expand Up @@ -54,7 +54,7 @@
}
}
},
"MyHttpApiGETHttpIntegration6f095b8469365f72e33fa33d9711b140516EBE31": {
"MyHttpApiGETRootIntegration5068C5B0": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
Expand Down Expand Up @@ -87,7 +87,7 @@
[
"integrations/",
{
"Ref": "MyHttpApiGETHttpIntegration6f095b8469365f72e33fa33d9711b140516EBE31"
"Ref": "MyHttpApiGETRootIntegration5068C5B0"
}
]
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { HttpApi, HttpMethod } from '@aws-cdk/aws-apigatewayv2';
import { LambdaProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import * as lambda from '@aws-cdk/aws-lambda';
import { App, Stack, CfnOutput } from '@aws-cdk/core';
import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib';
Expand Down Expand Up @@ -40,7 +40,7 @@ const handler = new lambda.Function(stack, 'lambda', {
httpApi.addRoutes({
path: '/',
methods: [HttpMethod.GET],
integration: new LambdaProxyIntegration({ handler }),
integration: new HttpLambdaIntegration('RootIntegration', handler),
authorizer,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"AutoDeploy": true
}
},
"MyHttpApiGETAuthorizerIntegMyHttpApiGET16D02385PermissionBB02EBFE": {
"MyHttpApiGETRootIntegratinPermissionCEEEB498": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
Expand Down Expand Up @@ -54,7 +54,7 @@
}
}
},
"MyHttpApiGETHttpIntegration6f095b8469365f72e33fa33d9711b140516EBE31": {
"MyHttpApiGETRootIntegratin93150A89": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
Expand Down Expand Up @@ -87,7 +87,7 @@
[
"integrations/",
{
"Ref": "MyHttpApiGETHttpIntegration6f095b8469365f72e33fa33d9711b140516EBE31"
"Ref": "MyHttpApiGETRootIntegratin93150A89"
}
]
]
Expand All @@ -101,10 +101,10 @@
"Ref": "MyHttpApi8AEAAC21"
},
"AuthorizerType": "JWT",
"Name": "UserPoolAuthorizer",
"IdentitySource": [
"$request.header.Authorization"
],
"Name": "UserPoolAuthorizer",
"JwtConfiguration": {
"Audience": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// !cdk-integ pragma:ignore-assets
import * as path from 'path';
import { HttpApi, HttpMethod } from '@aws-cdk/aws-apigatewayv2';
import { LambdaProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import * as cognito from '@aws-cdk/aws-cognito';
import * as lambda from '@aws-cdk/aws-lambda';
import { App, Stack } from '@aws-cdk/core';
Expand Down Expand Up @@ -37,6 +37,6 @@ const handler = new lambda.Function(stack, 'lambda', {
httpApi.addRoutes({
path: '/',
methods: [HttpMethod.GET],
integration: new LambdaProxyIntegration({ handler }),
integration: new HttpLambdaIntegration('RootIntegratin', handler),
authorizer,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HttpIntegrationType, HttpRouteIntegration, HttpRouteIntegrationBindOptions, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2';

export class DummyRouteIntegration extends HttpRouteIntegration {
constructor() {
super('DummyRouteIntegration');
}

public bind(_: HttpRouteIntegrationBindOptions) {
return {
payloadFormatVersion: PayloadFormatVersion.VERSION_2_0,
type: HttpIntegrationType.HTTP_PROXY,
uri: 'some-uri',
};
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Template } from '@aws-cdk/assertions';
import { HttpApi, HttpIntegrationType, HttpRouteIntegrationBindOptions, HttpRouteIntegration, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2';
import { HttpApi } from '@aws-cdk/aws-apigatewayv2';
import { Stack } from '@aws-cdk/core';
import { HttpJwtAuthorizer } from '../../lib';
import { DummyRouteIntegration } from './integration';

describe('HttpJwtAuthorizer', () => {
test('default', () => {
Expand Down Expand Up @@ -58,13 +59,3 @@ describe('HttpJwtAuthorizer', () => {
Template.fromStack(stack).resourceCountIs('AWS::ApiGatewayV2::Authorizer', 1);
});
});

class DummyRouteIntegration extends HttpRouteIntegration {
public bind(_: HttpRouteIntegrationBindOptions) {
return {
payloadFormatVersion: PayloadFormatVersion.VERSION_2_0,
type: HttpIntegrationType.HTTP_PROXY,
uri: 'some-uri',
};
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Match, Template } from '@aws-cdk/assertions';
import { HttpApi, HttpIntegrationType, HttpRouteIntegrationBindOptions, HttpRouteIntegration, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2';
import { HttpApi } from '@aws-cdk/aws-apigatewayv2';
import { Code, Function, Runtime } from '@aws-cdk/aws-lambda';
import { Duration, Stack } from '@aws-cdk/core';
import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib';
import { DummyRouteIntegration } from './integration';

describe('HttpLambdaAuthorizer', () => {

Expand Down Expand Up @@ -169,13 +170,3 @@ describe('HttpLambdaAuthorizer', () => {
});
});
});

class DummyRouteIntegration extends HttpRouteIntegration {
public bind(_: HttpRouteIntegrationBindOptions) {
return {
payloadFormatVersion: PayloadFormatVersion.VERSION_2_0,
type: HttpIntegrationType.HTTP_PROXY,
uri: 'some-uri',
};
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Template } from '@aws-cdk/assertions';
import { HttpApi, HttpIntegrationType, HttpRouteIntegrationBindOptions, HttpRouteIntegration, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2';
import { HttpApi } from '@aws-cdk/aws-apigatewayv2';
import { UserPool } from '@aws-cdk/aws-cognito';
import { Stack } from '@aws-cdk/core';
import { HttpUserPoolAuthorizer } from '../../lib';
import { DummyRouteIntegration } from './integration';

describe('HttpUserPoolAuthorizer', () => {
test('default', () => {
Expand Down Expand Up @@ -111,13 +112,3 @@ describe('HttpUserPoolAuthorizer', () => {
});
});
});

class DummyRouteIntegration extends HttpRouteIntegration {
public bind(_: HttpRouteIntegrationBindOptions) {
return {
payloadFormatVersion: PayloadFormatVersion.VERSION_2_0,
type: HttpIntegrationType.HTTP_PROXY,
uri: 'some-uri',
};
}
}
35 changes: 11 additions & 24 deletions packages/@aws-cdk/aws-apigatewayv2-integrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ proxy integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide
The following code configures a route `GET /books` with a Lambda proxy integration.

```ts
import { LambdaProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

declare const booksDefaultFn: lambda.Function;
const booksIntegration = new LambdaProxyIntegration({
handler: booksDefaultFn,
});
const booksIntegration = new HttpLambdaIntegration('BooksIntegration', booksDefaultFn);

const httpApi = new apigwv2.HttpApi(this, 'HttpApi');

Expand All @@ -68,11 +66,9 @@ The following code configures a route `GET /books` with an HTTP proxy integratio
`get-books-proxy.myproxy.internal`.

```ts
import { HttpProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { HttpUrlIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

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

const httpApi = new apigwv2.HttpApi(this, 'HttpApi');

Expand Down Expand Up @@ -106,9 +102,7 @@ listener.addTargets('target', {
});

const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpAlbIntegration({
listener,
}),
defaultIntegration: new HttpAlbIntegration('DefaultIntegration', listener),
});
```

Expand All @@ -129,9 +123,7 @@ listener.addTargets('target', {
});

const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpNlbIntegration({
listener,
}),
defaultIntegration: new HttpNlbIntegration('DefaultIntegration', listener),
});
```

Expand All @@ -154,9 +146,8 @@ const namespace = new servicediscovery.PrivateDnsNamespace(this, 'Namespace', {
const service = namespace.createService('Service');

const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpServiceDiscoveryIntegration({
defaultIntegration: new HttpServiceDiscoveryIntegration('DefaultIntegration', service, {
vpcLink,
service,
}),
});
```
Expand All @@ -179,8 +170,7 @@ listener.addTargets('target', {
});

const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpAlbIntegration({
listener,
defaultIntegration: new HttpAlbIntegration('DefaultIntegration', listener, {
parameterMapping: new apigwv2.ParameterMapping()
.appendHeader('header2', apigwv2.MappingValue.requestHeader('header1'))
.removeHeader('header1'),
Expand All @@ -200,8 +190,7 @@ listener.addTargets('target', {
});

const httpEndpoint = new apigwv2.HttpApi(this, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpAlbIntegration({
listener,
defaultIntegration: new HttpAlbIntegration('DefaultIntegration', listener, {
parameterMapping: new apigwv2.ParameterMapping().custom('myKey', 'myValue'),
}),
});
Expand All @@ -222,7 +211,7 @@ The API Gateway service will invoke the lambda function with an event payload of
The following code configures a `sendmessage` route with a Lambda integration

```ts
import { LambdaWebSocketIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';
import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations';

const webSocketApi = new apigwv2.WebSocketApi(this, 'mywsapi');
new apigwv2.WebSocketStage(this, 'mystage', {
Expand All @@ -233,8 +222,6 @@ new apigwv2.WebSocketStage(this, 'mystage', {

declare const messageHandler: lambda.Function;
webSocketApi.addRoute('sendmessage', {
integration: new LambdaWebSocketIntegration({
handler: messageHandler,
}),
integration: new WebSocketLambdaIntegration('SendMessageIntegration', messageHandler),
});
```
Loading