amazon-api-gateway-url-shortener icon indicating copy to clipboard operation
amazon-api-gateway-url-shortener copied to clipboard

Can I write the mapping templates (in api.yaml) using block strings?

Open juancpgo opened this issue 3 years ago • 1 comments

I'm struggling to figure out the right syntax to use in CloudFormation templates.

Is there a particular reason why the mapping templates were written with double quoted strings, as opposed to block strings?

responseTemplates:
  application/json: "#set($inputRoot = $input.path('$'))[ \
    #foreach($elem in $inputRoot.Items) { \
      \"id\":\"$elem.id.S\", \
      \"url\": \"$elem.url.S\", \
      \"timestamp\": \"$elem.timestamp.S\", \
      \"owner\": \"$elem.owner.S\"} \
    #if($foreach.hasNext),#end \
    #end]"

Using a multiline/block string seems so much more writable and readable:

responseTemplates:
  application/json: |-
    #set($inputRoot = $input.path('$'))[
      #foreach($elem in $inputRoot.Items) {
        "id": "$elem.id.S",
        "url": "$elem.url.S",
        "timestamp": "$elem.timestamp.S",
        "owner": "$elem.owner.S"}
      #if($foreach.hasNext),#end
    #end]

(this example is from api.yaml line 171)

juancpgo avatar Apr 30 '21 08:04 juancpgo

Ps: After consideration I finally got it: the developer probably generated the VTL code using the AWS console and copy/pasted to the template. So it wasn't a choice of syntax, it was just his way of "playing safe" and being productive.

Anyways.. sorry, I know this isn't really an "issue". But I was mistakenly thinking that maybe it had to be done that way (with double quoted strings).

juancpgo avatar May 01 '21 23:05 juancpgo