skip to Main Content

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?

2

Answers


  1. 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!

    Login or Signup to reply.
  2. I think

    {"message":$context.error.messageString}
    

    Would give you the results you wanted.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search