Skip to content

Commit 6a147b7

Browse files
chore(apigatewayv2): review readme (#27996)
API Review Session for `aws-apigatewayv2-alpha`, `aws-apigatewayv2-authorizers-alpha`, and `aws-apigatewayv2-integrations-alpha`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 986f54c commit 6a147b7

File tree

3 files changed

+27
-19
lines changed
  • packages/@aws-cdk

3 files changed

+27
-19
lines changed

packages/@aws-cdk/aws-apigatewayv2-alpha/README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ This module supports features under [API Gateway v2](https://docs.aws.amazon.com
4646
that lets users set up Websocket and HTTP APIs.
4747
REST APIs can be created using the `aws-cdk-lib/aws-apigateway` module.
4848

49+
HTTP and Websocket APIs use the same CloudFormation resources under the hood. However, this module separates them into two separate constructs for a more efficient abstraction since there are a number of CloudFormation properties that specifically apply only to each type of API.
50+
4951
## HTTP API
5052

5153
HTTP APIs enable creation of RESTful APIs that integrate with AWS Lambda functions, known as Lambda proxy integration,
@@ -65,16 +67,15 @@ integration, HTTP proxy integration and, AWS service integrations, also known as
6567
[Configuring integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations.html).
6668

6769
Integrations are available at the `aws-apigatewayv2-integrations` module and more information is available in that module.
68-
As an early example, the following code snippet configures a route `GET /books` with an HTTP proxy integration all
69-
configures all other HTTP method calls to `/books` to a lambda proxy.
70+
As an early example, we have a website for a bookstore where the following code snippet configures a route `GET /books` with an HTTP proxy integration. All other HTTP method calls to `/books` route to a default lambda proxy for the bookstore.
7071

7172
```ts
7273
import { HttpUrlIntegration, HttpLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';
7374

7475
const getBooksIntegration = new HttpUrlIntegration('GetBooksIntegration', 'https://get-books-proxy.example.com');
7576

76-
declare const booksDefaultFn: lambda.Function;
77-
const booksDefaultIntegration = new HttpLambdaIntegration('BooksIntegration', booksDefaultFn);
77+
declare const bookStoreDefaultFn: lambda.Function;
78+
const bookStoreDefaultIntegration = new HttpLambdaIntegration('BooksIntegration', bookStoreDefaultFn);
7879

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

@@ -86,7 +87,7 @@ httpApi.addRoutes({
8687
httpApi.addRoutes({
8788
path: '/books',
8889
methods: [ apigwv2.HttpMethod.ANY ],
89-
integration: booksDefaultIntegration,
90+
integration: bookStoreDefaultIntegration,
9091
});
9192
```
9293

@@ -310,9 +311,16 @@ The following code creates a `VpcLink` to a private VPC.
310311

311312
```ts
312313
import * as ec2 from 'aws-cdk-lib/aws-ec2';
314+
import * as elb from 'aws-cdk-lib/aws-elasticloadbalancingv2';
315+
import { HttpAlbIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';
313316

314317
const vpc = new ec2.Vpc(this, 'VPC');
318+
const alb = new elb.ApplicationLoadBalancer(this, 'AppLoadBalancer', { vpc });
319+
315320
const vpcLink = new apigwv2.VpcLink(this, 'VpcLink', { vpc });
321+
322+
// Creating an HTTP ALB Integration:
323+
const albIntegration = new HttpAlbIntegration('ALBIntegration', alb.listeners[0], {});
316324
```
317325

318326
Any existing `VpcLink` resource can be imported into the CDK app via the `VpcLink.fromVpcLinkAttributes()`.

packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@
3333
## Introduction
3434

3535
API Gateway supports multiple mechanisms for controlling and managing access to your HTTP API. They are mainly
36-
classified into Lambda Authorizers, JWT authorizers and standard AWS IAM roles and policies. More information is
36+
classified into Lambda Authorizers, JWT authorizers, and standard AWS IAM roles and policies. More information is
3737
available at [Controlling and managing access to an HTTP
3838
API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-access-control.html).
3939

4040
## HTTP APIs
4141

42-
Access control for Http Apis is managed by restricting which routes can be invoked via.
42+
Access control for HTTP APIs is managed by restricting which routes can be invoked via.
4343

44-
Authorizers and scopes can either be applied to the api, or specifically for each route.
44+
Authorizers and scopes can either be applied to the API, or specifically for each route.
4545

4646
### Default Authorization
4747

48-
When using default authorization, all routes of the api will inherit the configuration.
48+
When using default authorization, all routes of the API will inherit the configuration.
4949

5050
In the example below, all routes will require the `manage:books` scope present in order to invoke the integration.
5151

@@ -65,12 +65,12 @@ const api = new apigwv2.HttpApi(this, 'HttpApi', {
6565

6666
### Route Authorization
6767

68-
Authorization can also configured for each Route. When a route authorization is configured, it takes precedence over default authorization.
68+
Authorization can also be configured for each Route. When a route authorization is configured, it takes precedence over default authorization.
6969

7070
The example below showcases default authorization, along with route authorization. It also shows how to remove authorization entirely for a route.
7171

7272
- `GET /books` and `GET /books/{id}` use the default authorizer settings on the api
73-
- `POST /books` will require the [write:books] scope
73+
- `POST /books` will require the `['write:books']` scope
7474
- `POST /login` removes the default authorizer (unauthenticated route)
7575

7676
```ts
@@ -120,7 +120,7 @@ JWT authorizers allow the use of JSON Web Tokens (JWTs) as part of [OpenID Conne
120120

121121
When configured, API Gateway validates the JWT submitted by the client, and allows or denies access based on its content.
122122

123-
The location of the token is defined by the `identitySource` which defaults to the http `Authorization` header. However it also
123+
The location of the token is defined by the `identitySource` which defaults to the HTTP `Authorization` header. However it also
124124
[supports a number of other options](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html#http-api-lambda-authorizer.identity-sources).
125125
It then decodes the JWT and validates the signature and claims, against the options defined in the authorizer and route (scopes).
126126
For more information check the [JWT Authorizer documentation](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html).
@@ -150,7 +150,7 @@ api.addRoutes({
150150

151151
#### User Pool Authorizer
152152

153-
User Pool Authorizer is a type of JWT Authorizer that uses a Cognito user pool and app client to control who can access your Api. After a successful authorization from the app client, the generated access token will be used as the JWT.
153+
User Pool Authorizer is a type of JWT Authorizer that uses a Cognito user pool and app client to control who can access your API. After a successful authorization from the app client, the generated access token will be used as the JWT.
154154

155155
Clients accessing an API that uses a user pool authorizer must first sign in to a user pool and obtain an identity or access token.
156156
They must then use this token in the specified `identitySource` for the API call. More information is available at [using Amazon Cognito user

packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Integrations connect a route to backend resources. HTTP APIs support Lambda prox
3434
Lambda integrations enable integrating an HTTP API route with a Lambda function. When a client invokes the route, the
3535
API Gateway service forwards the request to the Lambda function and returns the function's response to the client.
3636

37-
The API Gateway service will invoke the lambda function with an event payload of a specific format. The service expects
38-
the function to respond in a specific format. The details on this format is available at [Working with AWS Lambda
37+
The API Gateway service will invoke the Lambda function with an event payload of a specific format. The service expects
38+
the function to respond in a specific format. The details on this format are available at [Working with AWS Lambda
3939
proxy integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
4040

4141
The following code configures a route `GET /books` with a Lambda proxy integration.
@@ -204,11 +204,11 @@ WebSocket integrations connect a route to backend resources. The following integ
204204
### Lambda WebSocket Integration
205205

206206
Lambda integrations enable integrating a WebSocket API route with a Lambda function. When a client connects/disconnects
207-
or sends message specific to a route, the API Gateway service forwards the request to the Lambda function
207+
or sends a message specific to a route, the API Gateway service forwards the request to the Lambda function
208208

209-
The API Gateway service will invoke the lambda function with an event payload of a specific format.
209+
The API Gateway service will invoke the Lambda function with an event payload of a specific format.
210210

211-
The following code configures a `sendmessage` route with a Lambda integration
211+
The following code configures a `sendMessage` route with a Lambda integration
212212

213213
```ts
214214
import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha';
@@ -221,7 +221,7 @@ new apigwv2.WebSocketStage(this, 'mystage', {
221221
});
222222

223223
declare const messageHandler: lambda.Function;
224-
webSocketApi.addRoute('sendmessage', {
224+
webSocketApi.addRoute('sendMessage', {
225225
integration: new WebSocketLambdaIntegration('SendMessageIntegration', messageHandler),
226226
});
227227
```

0 commit comments

Comments
 (0)