如何在 AWS Api 网关映射模板中使用 IF 条件。我可以使用 if 条件而不使用 foreach 吗?

kat*_*k S 4 amazon-web-services amazon-dynamodb aws-api-gateway

#if($inputRoot.objectType == 'Test'), "TableName": "StudentTests", #else,"TableName": "UserActions", #end

如果使用 if 条件,我在邮递员链接中遇到错误 ## "__type": "com.amazon.coral.service#SerializationException" ##

BTL*_*BTL 7

我理解你的问题的方式是:

#if($inputRoot.objectType == "Test")
    #set($tableName = "StudentTests"
#else
    #set($tableName = "UserActions"
#end

{
    "TableName": "$tableName",
    "Key": ...
}

Run Code Online (Sandbox Code Playgroud)