katik S
katik S

Reputation: 41

How to use IF condition in AWS Api gateway mapping templates. can i use if condition without using foreach?

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

if use if condition i got an error in postman link ## "__type": "com.amazon.coral.service#SerializationException" ##

Upvotes: 4

Views: 7983

Answers (1)

BTL
BTL

Reputation: 4666

The way I understand your question I would do :

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

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

Upvotes: 7

Related Questions