Skip to content

Commit

Permalink
some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alanraison committed Aug 30, 2021
1 parent 3da6a9f commit 1a9efab
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
51 changes: 51 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2-integrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,57 @@ const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
});
```

### AWS Service Integrations

AWS Service integrations allow for API Gateway to integrate directly with the following AWS Services:

- EventBridge
- PutEvents
- SQS
- SendMessage
- ReceiveMessage
- DeleteMessage
- PurgeQueue
- Kinesis
- PutRecord
- Step Functions
- StartExecution
- StartSyncExecution
- StopExecution

The following code configures a `message` route, which creates an SQS message containing the request body:

```ts
const queue = new Queue(stack, 'Queue');
const httpApi = new HttpApi(stack, 'IntegrationApi');

const role = new Role(stack, 'SQSRole', {
assumedBy: new ServicePrincipal('apigateway.amazonaws.com'),
});
role.addToPrincipalPolicy(new PolicyStatement({
actions: ['sqs:*'],
resources: [queue.queueArn],
}));

httpApi.addRoutes({
path: '/message',
methods: [HttpMethod.POST],
integration: new SqsSendMessageIntegration({
role,
body: StringMappingExpression.fromMapping(Mapping.fromRequestBody()),
queue: QueueMappingExpression.fromQueue(queue),
}),
});
```

Integrations should always specify a role, with appropriate permissions to allow the actions.

All other integration properties, except for the `region` can be either set up by the CDK, or
specified in the request, context variables or stage variables. The various `MappingExpression`
classes assist with creating these properties; each can be constructed from the type it represents,
or from a `Mapping` from the request, context or scope, as described in the
[API Gateway documentation](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-aws-services.html#http-api-develop-integrations-aws-services-parameter-mapping).

## WebSocket APIs

WebSocket integrations connect a route to backend resources. The following integrations are supported in the CDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const app = new App();
const stack = new Stack(app, 'integ-sqs');
const httpApi = new HttpApi(stack, 'IntegrationApi');

const queue = new Queue(stack, 'Queue', {
});
const queue = new Queue(stack, 'Queue');
const queueMapping = QueueMappingExpression.fromQueue(queue);

const role = new Role(stack, 'SQSRole', {
Expand Down

0 comments on commit 1a9efab

Please sign in to comment.