Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d310726
(feat)apigatewayv2: initial L2 support
pahud Feb 25, 2020
bef371a
Merge branch 'master' into apigatewayv2-L2
pahud Feb 25, 2020
2ba95d8
add the expected.json for integ test
pahud Feb 25, 2020
9f08ed4
fix package.json
pahud Feb 25, 2020
075e564
merge from master
pahud Mar 13, 2020
febd6a3
udpate README
pahud Mar 13, 2020
33dead4
update README
pahud Mar 13, 2020
02f96c2
update README
pahud Mar 13, 2020
46d3be4
remove comments and minor fix
pahud Mar 13, 2020
7265479
fix package.json
pahud Mar 13, 2020
35b8ddf
add integration and tests
pahud Mar 14, 2020
66c5022
update README
pahud Mar 14, 2020
87fbe4b
minor fix
pahud Mar 14, 2020
d26ad33
support HttpApi with no integration and no route
pahud Mar 14, 2020
4b278c0
update tests
pahud Mar 14, 2020
bef8974
remove unused type
pahud Mar 14, 2020
068b476
update integ test
pahud Mar 14, 2020
6f8f64d
support addLambdaRoute and addHttpRoute from HttpApi
pahud Mar 15, 2020
9d986d5
update README sample
pahud Mar 16, 2020
d338c41
Merge branch 'master' into apigatewayv2-L2
pahud Mar 16, 2020
32b6a31
Merge branch 'master' into apigatewayv2-L2
pahud Mar 18, 2020
b200c9f
Update packages/@aws-cdk/aws-apigatewayv2/README.md
pahud Mar 18, 2020
0bea7fc
Update packages/@aws-cdk/aws-apigatewayv2/README.md
pahud Mar 18, 2020
822cfe8
Update packages/@aws-cdk/aws-apigatewayv2/README.md
pahud Mar 18, 2020
c20a448
minor fix
pahud Mar 18, 2020
b6415e3
Merge branch 'master' into apigatewayv2-L2
pahud Mar 18, 2020
1965f59
update package.json
pahud Mar 18, 2020
6547860
update integ
pahud Mar 18, 2020
0989585
support api.addRootRoute()
pahud Mar 23, 2020
330b4af
Merge branch 'master' of https://github.com/aws/aws-cdk into apigatew…
pahud Mar 26, 2020
90204bb
support addRoutes() fro `HttpApi` and `Route` resources.
pahud Mar 26, 2020
818af1d
Merge branch 'master' into apigatewayv2-L2
Apr 27, 2020
3568779
trying to move this forward
Apr 27, 2020
7b64fd0
working basic routes and lambda integration
Apr 28, 2020
bb8857f
Working stage
Apr 28, 2020
5f44349
default integration
Apr 28, 2020
9e4deb8
docs updated & tweaks
Apr 29, 2020
35d6341
the massive restructure
Apr 29, 2020
cce22c1
Added IHttpRoute and fixed up HttpProxyIntegration
Apr 29, 2020
edba63c
http proxy now works
Apr 29, 2020
0b404dc
move stage name back to string
Apr 29, 2020
d9cd335
unit and integ tests
Apr 29, 2020
a5e2b20
addRoutes()
Apr 30, 2020
48aa1af
tests for integrations
Apr 30, 2020
ea8bea9
Merge pull request #1 from pahud/nija-at/apigwv2-pattern-setup
pahud Apr 30, 2020
c18a7d0
update README
pahud May 4, 2020
113053d
Merge branch 'master' into apigatewayv2-L2
pahud May 4, 2020
8ded78b
Update README.md
pahud May 4, 2020
df21f0f
Update package.json
pahud May 4, 2020
b808736
language and structural adjustments to the README
May 4, 2020
7cc71e0
adjust http integration
May 4, 2020
64606f3
Merge branch 'master' into apigatewayv2-L2
mergify[bot] May 4, 2020
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
127 changes: 125 additions & 2 deletions packages/@aws-cdk/aws-apigatewayv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,132 @@
---
<!--END STABILITY BANNER-->


This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project.

`aws-apigatewayv2` supports the `HTTP` API for Amazon API Gateway.

## Examples:

### HTTP API with Lambda proxy integration as the `$default` route

```ts
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'ApiagtewayV2HttpApi');

const handler = new lambda.Function(stack, 'MyFunc', {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
code: new lambda.InlineCode(`
import json
def handler(event, context):
return {
'statusCode': 200,
'body': json.dumps(event)
}`),
});

// Create a HTTP API with Lambda Proxy Integration as $default route
const api = new apigatewayv2.LambdaProxyApi(stack, 'LambdaProxyApi', {
handler
});
```
### HTTP API with HTTP proxy integration as the `$default` route

```ts
new apigatewayv2.HttpProxyApi(stack, 'HttpProxyApi', {
url: 'https://aws.amazon.com'
});
```

## Root Route

Create the `root(/)` route of the API

```ts
import apigatewayv2 = require('@aws-cdk/aws-apigatewayv2');

// prepare the root handler function
const rootHandler = new lambda.Function(stack, 'RootFunc', {
runtime: lambda.Runtime.PYTHON_3_7,
handler: 'index.handler',
code: new lambda.InlineCode(`
import json, os
def handler(event, context):
whoami = os.environ['WHOAMI']
http_path = os.environ['HTTP_PATH']
return {
'statusCode': 200,
'body': json.dumps({ 'whoami': whoami, 'http_path': http_path })
}`),
environment: {
WHOAMI: 'root',
HTTP_PATH: '/'
},
});


// create a HTTP API with Lambda Proxy Integration as $default route
const api = new apigatewayv2.LambdaProxyApi(stack, 'LambdaProxyApi', {
handler
});

// create the root route(/) with HTTP ANY method and Lambda integration
api.root = new apigatewayv2.LambdaRoute(stack, 'RootRoute', {
api,
handler: rootHandler,
httpPath: '/',
});

// create child routes from the root
api.root
// HTTP GET /foo
.addLambdaRoute('foo', 'Foo', {
target: handler,
method: apigatewayv2.HttpMethod.GET
})
// HTTP ANY /foo/checkip
.addHttpRoute('checkip', 'FooCheckIp', {
targetUrl: 'https://checkip.amazonaws.com',
method: apigatewayv2.HttpMethod.ANY
});
```

## Create any route with no `root`

If we just need a specific route like `/some/very/deep/route/path` without the `root(/)` and make all requests to other paths go to the `$default`, we can simply create it like this:

```ts
// create a HTTP API with HTTP Proxy Integration as the $default
new apigatewayv2.HttpProxyApi(stack, 'HttpProxyApi', {
url: 'https://aws.amazon.com'
});


// create a specific route
const someDeepLambdaRoute = new apigatewayv2.LambdaRoute(stack, 'SomeLambdaRoute', {
api,
handler,
httpPath: '/some/very/deep/route/path',
});

// print the full http url for this route
new cdk.CfnOutput(stack, 'RouteURL', {
value: someDeepLambdaRoute.fullUrl
});

// and build even more child routes from here
someDeepLambdaRoute
// HTTP ANY /some/very/deep/route/path/bar
.addLambdaRoute('bar', 'SomeDeepPathBar', {
target: handler,
method: apigatewayv2.HttpMethod.GET
})
// HTTP ANY /some/very/deep/route/path/bar/checkip
.addHttpRoute('checkip', 'SomeDeepPathBarCheckIp', {
targetUrl: 'https://checkip.amazonaws.com',
method: apigatewayv2.HttpMethod.ANY
});
```
Loading