amazon-web-servicesaws-api-gatewayvelocity

How to use a Velocity variable in an AWS API Gateway Response template?


I'm unable to use a variable in an API Gateway Response

Here's a simplified example of a Response template I use to test variable usage

#set( $message= "message" )
{$message:$context.error.messageString}

This is the response that I expect

{
  message : "Unauthorized"
}

This is the actual response:

#set( = "message" )
{
    : "Unauthorized"
}

This is similar to the Hello Velocity World! example as described in the Apache Velocity Engine - User Guide

What am I doing wrong here?


Solution

  • I ran into the same issue. I needed to perform logic to map my responses correctly. Ended up stumbling on this: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.responseTemplates.html which flat out says "we don't parse VTL in gateway responses".

    Hope that helps!