【问题标题】:Dot after Reference in Body Mapping Template (AWS API Gateway)身体映射模板中引用后的点(AWS API 网关)
【发布时间】:2018-12-16 23:55:39
【问题描述】:

是否可以在 API Gateway 的正文映射模板中的引用后直接使用点?

我像这样进行字符串连接:

#set($region = "us-east-2")
#set($apiid = "$context.apiId")
#set($stage = "$context.stage")
#set($path = "search/stac")

"url": "https://$apiid.execute-api.$region.amazonaws.com/$stage/$path"

问题是 $apiid 和 $region 没有被取消引用。结果如下所示。

"url: "https:// .execute-api. .amazonaws.com/dev/search/stac

如果我使用没有字符串连接的引用,它们具有预期值。所以 #set 操作似乎是正确的。

我认为它会将引用后的点误认为是函数调用。 Velocity 模板语言中的点如何转义?

【问题讨论】:

    标签: amazon-web-services aws-api-gateway string-concatenation vtl apache-velocity


    【解决方案1】:

    你可以使用curly braces来标记变量的开始和结束:

    "url": "https://${apiid}.execute-api.${region}.amazonaws.com/$stage/$path"
    

    如果您需要明确地将 Velocity 指令与周围的文本分开,可以将其包裹在花括号({ 和 })中:

    【讨论】:

    • 效果很好!感谢您的快速回复。
    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 2018-12-04
    • 2017-06-24
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2018-07-01
    • 2020-09-28
    相关资源
    最近更新 更多