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

feat(apigatewayv2-integrations): http api - support for request parameter mapping #15630

Merged
merged 23 commits into from
Oct 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1886a8b
Add parameter mapping support, readme update
Jul 18, 2021
3f2078f
Update packages/@aws-cdk/aws-apigatewayv2-integrations/README.md
dan-lind Jul 29, 2021
6703f2c
Update packages/@aws-cdk/aws-apigatewayv2-integrations/README.md
dan-lind Jul 29, 2021
1e2c799
Update packages/@aws-cdk/aws-apigatewayv2-integrations/README.md
dan-lind Jul 29, 2021
6d3aa5f
Merge branch 'master' into add-requestparams-support-apigatewayv2
dan-lind Jul 29, 2021
8b36ecc
Update packages/@aws-cdk/aws-apigatewayv2-integrations/README.md
dan-lind Jul 30, 2021
0c81a2a
Fix ParameterMapping example
Jul 30, 2021
b1f6d15
Add first unit test
Aug 5, 2021
e5d5374
Remove logging
Aug 5, 2021
fbc06b8
Simplyfy API
Aug 24, 2021
4ce0dc6
Merge branch 'master' into add-requestparams-support-apigatewayv2
dan-lind Aug 24, 2021
97df41e
Merge branch 'master' into add-requestparams-support-apigatewayv2
dan-lind Oct 3, 2021
8856e00
Fix README, move parameter-mapping to separate class
Oct 3, 2021
0dce9a1
Merge branch 'add-requestparams-support-apigatewayv2' of https://gith…
Oct 3, 2021
ed2c1f3
Fix README, move parameter-mapping to separate class
Oct 3, 2021
8da3978
Implementation for higher level constructs, docs update, unit tests
Oct 4, 2021
b3d1963
Fix imports
Oct 4, 2021
8d3abb6
Merge branch 'master' into add-requestparams-support-apigatewayv2
dan-lind Oct 4, 2021
42ef243
Apply suggestions from code review
Oct 13, 2021
74a4ce1
Apply suggestions from code review
Oct 13, 2021
3ddef7d
Merge branch 'master' into add-requestparams-support-apigatewayv2
dan-lind Oct 13, 2021
bc284d5
Merge branch 'master' into add-requestparams-support-apigatewayv2
dan-lind Oct 13, 2021
69cef43
Merge branch 'master' into add-requestparams-support-apigatewayv2
mergify[bot] Oct 13, 2021
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
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 @@ -21,6 +21,7 @@
- [Lambda Integration](#lambda)
- [HTTP Proxy Integration](#http-proxy)
- [Private Integration](#private-integration)
- [Request Parameter mapping](#request-parameters)
dan-lind marked this conversation as resolved.
Show resolved Hide resolved
- [WebSocket APIs](#websocket-apis)
- [Lambda WebSocket Integration](#lambda-websocket-integration)

Expand Down Expand Up @@ -149,6 +150,56 @@ const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
});
```

### Request parameter mapping

dan-lind marked this conversation as resolved.
Show resolved Hide resolved
### Request Parameters

dan-lind marked this conversation as resolved.
Show resolved Hide resolved
Request parameter mapping is supported through a set of helper methods.
The following example renames a request header from header1 to header2 by generating mappings
`append:header.header2: $request.header.header1` and `remove:header.header1: ''`:

```ts
const vpc = new ec2.Vpc(stack, 'VPC');
const lb = new elbv2.ALB(stack, 'lb', { vpc });
const listener = lb.addListener('listener', { port: 80 });
listener.addTargets('target', {
port: 80,
});

const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpAlbIntegration({
listener,
requestParameters: new RequestParameters()
.addParameter({
dan-lind marked this conversation as resolved.
Show resolved Hide resolved
mappingKey: HttpMappingKey.appendHeader('header2'),
mappingValue: MappingValue.requestHeader('header1'),
})
.addParameter({
mappingKey: HttpMappingKey.removeHeader(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you meant to say HttpMappingKey.removeHeader('header1') ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I will fix that!

mappingValue: MappingValue.NONE,
}),
}),
});
```



To use values which does not yet have any helper functions, you can use the custom methods:
nija-at marked this conversation as resolved.
Show resolved Hide resolved

```ts
const httpEndpoint = new HttpApi(stack, 'HttpProxyPrivateApi', {
defaultIntegration: new HttpAlbIntegration({
listener,
requestParameters: new RequestParameters()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ParameterMapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

.addParameter({
mappingKey: MappingKey.custom('new.header'),
mappingValue: MappingValue.custom('new.value'),
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just

new ParameterMapping().custom('new.header', MappingValue.custom('new.value'))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@nija-at nija-at Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's not fixed though? It's still the same in the README.

EDIT: Ahh, I see you fixed the API but not the README,

}),
});
```


## WebSocket APIs

WebSocket integrations connect a route to backend resources. The following integrations are supported in the CDK.
Expand Down