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

Conversation

dan-lind
Copy link
Contributor


This is an initial PR as discussed with @nija-at in an attempt to describe the user experience for supporting parameter mapping.
This PR will only support parameter mappings for HTTP APIs without an integration subtypes, but it will provide interfaces that can (and probably should) be reused when adding support for integration subtypes as well. Since it also provides the possibility to provide custom key/value pairs for maximum flexibility, it can support and integration subtype although it requires a bit more work on the user side.

closes #15293

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Jul 18, 2021

@peterwoodworth peterwoodworth added the @aws-cdk/aws-apigatewayv2-integrations Related to AWS APIGatewayv2 Integrations label Jul 20, 2021
@nija-at nija-at added effort/medium Medium work item – several days of effort p1 labels Jul 28, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR. Sorry for the delay.

So nice to review a README change before seeing all the code that implements it.

Some comments below. Let me know what you think.

packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
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!

packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
@nija-at nija-at changed the title feat(apigatewayv2-integrations): Add option to pass request parameter mappings feat(apigatewayv2-integrations): http api - request parameter mapping Jul 28, 2021
dan-lind and others added 3 commits July 29, 2021 07:40
Co-authored-by: Niranjan Jayakar <nija@amazon.com>
Co-authored-by: Niranjan Jayakar <nija@amazon.com>
Co-authored-by: Niranjan Jayakar <nija@amazon.com>
@mergify mergify bot dismissed nija-at’s stale review July 29, 2021 05:41

Pull request has been modified.

@dan-lind
Copy link
Contributor Author

@nija-at I think I have adressed all your comments now, should I go ahead with a first iteration of the implementation?

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

@nija-at I think I have adressed all your comments now, should I go ahead with a first iteration of the implementation?

@dan-lind - Yes, go forth.

Setting the PR status to 'request changes' so our automation knows that the ball is now in your court.

@mergify mergify bot dismissed nija-at’s stale review August 5, 2021 05:33

Pull request has been modified.

@dan-lind
Copy link
Contributor Author

dan-lind commented Aug 5, 2021

@nija-at I've made a first attempt at implementation, only in the base HttpIntegration at this point. Would like some feedback on this before I continue with the higher level construct for the ALB.

Creating the mappings is slightly different from what we discussed, you would now create parameter mappings like this

parameterMapping: new ParameterMapping(
  [
    {
      key: HttpMappingKey.appendHeader('header2'),
      value: MappingValue.requestHeader('header1'),
    },
    {
      key: HttpMappingKey.removeHeader('header1'),
      value: MappingValue.NONE,
    },
  ],
),

The idea was to lay the foundation which can later be reused when adding support for parameter mappings with integration subtypes (not in this PR). The same structure can then be used without much change, maybe it would look something like this for SQS

parameterMapping: new ParameterMapping(
  [
    {
      key: SqsMappingKey.QUEUE_URL,
      value: MappingValue.requestHeader('queueUrl'),
    },
    {
      key: SqsMappingKey.MESSAGE_BODY,
      value: MappingValue.requestBody('message'),
    },
  ],
),

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Hi @dan-lind. See my comments below.

readonly value: IMappingValue,
};

export class ParameterMapping {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move all of these classes and interfaces into their own file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I still should? Only one class left

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think you still should.

Copy link
Contributor

Choose a reason for hiding this comment

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

These should also move into the base apigateway module.

Comment on lines 77 to 88
export interface IMappingKey {
key: string;
};

export interface IMappingValue {
value: string;
};

export class MappingKey implements IMappingKey {
public static custom(mappingKey: string) {return new MappingKey(mappingKey); }
protected constructor(public readonly key: string) {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not clear why we need these classes and interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

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

Comment on lines 190 to 193
.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,

@@ -174,6 +175,18 @@ describe('HttpRoute', () => {
connectionType: HttpConnectionType.VPC_LINK,
uri: 'some-target-arn',
secureServerName: 'some-server-name',
parameterMapping: new ParameterMapping(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a separate unit test for parameter mapping instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 179 to 189
[
{
key: HttpMappingKey.appendHeader('header2'),
value: MappingValue.requestHeader('header1'),
},
{
key: HttpMappingKey.removeHeader('header1'),
value: MappingValue.NONE,
},
],
),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the API we decided, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See latest changes

@mergify mergify bot dismissed nija-at’s stale review August 24, 2021 04:31

Pull request has been modified.

@dan-lind
Copy link
Contributor Author

@nija-at Haven't been able to look at this for a while, but I've pushed some updates now, let me know if this addresses the concerns you had.

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me @dan-lind

Can you add docs, get the build to succeed and update the PR description? This should be close to shipping with one more iteration.

Comment on lines 190 to 193
.addParameter({
mappingKey: MappingKey.custom('new.header'),
mappingValue: MappingValue.custom('new.value'),
}),
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,

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.

same here

readonly value: IMappingValue,
};

export class ParameterMapping {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think you still should.

readonly value: IMappingValue,
};

export class ParameterMapping {
Copy link
Contributor

Choose a reason for hiding this comment

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

These should also move into the base apigateway module.

@mergify mergify bot dismissed nija-at’s stale review October 3, 2021 05:00

Pull request has been modified.

@dan-lind
Copy link
Contributor Author

dan-lind commented Oct 3, 2021

Sorry, not a lot of bandwidth currently, but I've tried to address your comments.
Not sure if I moved the new parameter-mappning.ts, let me know if it show move again.

I think what's left is also the actual implementation in the higher level constructs in the apigatewayv2-integrations module, but guess this is only applicable for ALB?

@dan-lind
Copy link
Contributor Author

dan-lind commented Oct 4, 2021

Couldn't find anything in the docs that suggests that there are any limits to where the parameter mapping is valid, so I've added them for all higher level constructs in the apigatewayv2-integrations module.

I´ve added docs and tests as well. Hopefully close to complete now

@dan-lind dan-lind changed the title feat(apigatewayv2-integrations): http api - request parameter mapping feat(apigatewayv2-integrations): http api - add support for request parameter mapping Oct 4, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Looks good.

packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-apigatewayv2-integrations/README.md Outdated Show resolved Hide resolved
nija-at
nija-at previously approved these changes Oct 13, 2021
@mergify mergify bot dismissed nija-at’s stale review October 13, 2021 12:13

Pull request has been modified.

@dan-lind
Copy link
Contributor Author

@nija-at Build failed after you approved, probably was too much behind master. I've synced with master now, can you please approve again?

@nija-at nija-at changed the title feat(apigatewayv2-integrations): http api - add support for request parameter mapping feat(apigatewayv2-integrations): http api - support for request parameter mapping Oct 13, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 13, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 69cef43
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 0452aed into aws:master Oct 13, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 13, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…eter mapping (aws#15630)

----
This is an initial PR as discussed with @nija-at in an attempt to describe the user experience for supporting parameter mapping.
This PR will only support parameter mappings for HTTP APIs _without_ an integration subtypes, but it will provide interfaces that can (and probably should) be reused when adding support for integration subtypes as well. Since it also provides the possibility to provide custom key/value pairs for maximum flexibility, it can support and integration subtype although it requires a bit more work on the user side.

closes aws#15293 

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigatewayv2-integrations Related to AWS APIGatewayv2 Integrations effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@aws-cdk/aws-apigatewayv2-integrations] support parameter mapping in Http Integrations
4 participants