Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 575
wysguy Avatar asked Oct 22 '25 00:10

wysguy


1 Answers

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!

like image 167
ATSnipes Avatar answered Oct 24 '25 15:10

ATSnipes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!