Aws-sam-cli: Support request validators and request/response mappings

Created on 9 Feb 2018  Â·  7Comments  Â·  Source: aws/aws-sam-cli

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 :)

arelocastart-api priorit3-long-term stagpm-review typfeature

Most helpful comment

@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.

All 7 comments

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

@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.

Thanks Eric!

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 notifications@github.com 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
.

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"}'

@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?

@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).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asyba picture asyba  Â·  3Comments

Caian picture Caian  Â·  3Comments

goldenbearkin picture goldenbearkin  Â·  3Comments

XDanny322 picture XDanny322  Â·  3Comments

dschu-lab picture dschu-lab  Â·  3Comments