aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Support request validators and request/response mappings

Open kadrach opened this issue 8 years ago • 8 comments

It would be great if aws-sam-local could support the request validation features of the APIGateway and request/response mappings with Velocity templates! Alternatively a log message on local calls that these parts of the definition are being ignored :)

kadrach avatar Feb 09 '18 03:02 kadrach

Hi guys. Any progress on this? This is a really important feature. Thanks

brunofitas avatar Jul 02 '18 13:07 brunofitas

@brunofitas @kadrach I have implemented this functionality locally https://github.com/ejhayes/aws-sam-cli.

To use templates, just need to add the velocity template to the x-amazon-apigateway-integration under requestTemplates, for example:

x-amazon-apigateway-integration:
	...
	requestTemplates:
	  application/json: "...VTL TEMPLATE HERE..."
	...

The velocity template mapping and JSONPath looks to be working fine, but java specific string functions like replaceAll will not work. For example $util.escapeJavaScript($input.json('$.errorMessage')) would work, but $util.escapeJavaScript($input.json('$.errorMessage')).replaceAll("\\'","'") would not.

Hoping to have a PR opened in the next couple days.

ejhayes avatar Oct 31 '18 23:10 ejhayes

Thanks Eric!

brunofitas avatar Nov 01 '18 11:11 brunofitas

Awesome one Eric!!!

Look forward to the PR and shout out if you need a hand to us

On Thu, 1 Nov 2018 at 11:35, Bruno Fitas [email protected] wrote:

Thanks Eric!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/awslabs/aws-sam-cli/issues/299#issuecomment-435013952, or mute the thread https://github.com/notifications/unsubscribe-auth/ADL4BKjUWsqCbEW5WwF80StnUH4hNKbRks5uqtyEgaJpZM4R_YT6 .

heitorlessa avatar Nov 01 '18 13:11 heitorlessa

Hi, will this going to be implemented ? also @ejhayes, is your pull request only cater the x-amazon-apigateway-integration ? As my template is came from the CDK and something like this

      Integration:
        ContentHandling: CONVERT_TO_TEXT
        IntegrationHttpMethod: POST
        IntegrationResponses:
          - ResponseParameters:
              method.response.header.Access-Control-Allow-Origin: "'*'"
            ResponseTemplates:
              application/json: "{\"data\": $input.json('$')}"
            StatusCode: "200"
          - ResponseParameters:
              method.response.header.Access-Control-Allow-Origin: "'*'"
            ResponseTemplates:
              application/json: "{\"message\":\"$input.path('$.message')\"}"
            SelectionPattern: .*Exception.*|.*error.*
            StatusCode: "400"
        PassthroughBehavior: WHEN_NO_TEMPLATES
        RequestTemplates:
          image/jpeg: '{"base64Image":"$input.body","token":"$input.header.Authorization"}'

hanstf avatar Sep 20 '19 16:09 hanstf

@jfuss or others? Is this in the aws sam cli roadmap at all? This issue is more then 2 years old, had contributing PR that was rejected, so is it being worked on at all?

rv2673 avatar Jul 07 '20 10:07 rv2673

@jfuss I would like to restart this PR. I understand the concerns about adding new dependencies. How about implementing only $input.json('$') and $input.params().path['paramname'], for example, instead? I mean we can choose a few and often used template mappings and implement them without introducing new dependencies. The implementation should look like simple string replacements (e.g. replacing "$input.json('$')" with body).

hirosato avatar Oct 05 '20 09:10 hirosato

Thanks for your interest in this feature request. We are hesitant to merge this today because with the current resources we would not be able to commit to maintaining this feature in the long run - maintain feature parity and fix issues with the implementation in a timely manner. Given the reaction we can see that this is important to the community and we recommend one of the two alternatives -

  1. We highly recommend you to use SAM Accelerate to test this in your development environment in the cloud. Here is a helpful video to learn more about it, and here is the installation instructions for the beta version. Please let us know if this helps with your testing needs.
  2. If testing in the cloud is not an option for you, we are considering adding plugin support if there is enough interest. Upvote and comment on this tracking issue, if building this as a plugin would be something you would be interested in instead.

praneetap avatar Sep 25 '21 03:09 praneetap