amazon-api-gateway-url-shortener
amazon-api-gateway-url-shortener copied to clipboard
Can I write the mapping templates (in api.yaml) using block strings?
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)
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).