AWS API Gateway Integration Response - calculate hmac hash

0

I am using webhook endpoint to push messages to SQS service

pipeline looks:

gateway -> integration request -> SQS -> integration response 

everything works fine but now third party integration requires time-to-time validation request, and i need to return calculated hmac sha256 hash in response

Not sure if response template support all utils, but I am trying next Integration response template:

#set($token = $context.responseOverride.header.RequestBody)

#if(!$token || $token == '')
    {"status": "ok"}
#else
    #set($secretKey = "my-secret-key")
    #set($hmac = $util.cryptoHmac("HmacSHA256", "$token", $secretKey))

    {
        "token": "$message",
        "hmac": "$util.base64Encode($hmac)"
    }
#end

but looks like $util.cryptoHmac("HmacSHA256", "$token", $secretKey) not working, method returns null

maybe somebody could help me to resolve this case

1 Answer
0

Hi,

The Amazon API Gateway $util variable just supports the following functions:

  • escapeJavaScript
  • parseJson
  • urlEncode
  • urlDecode
  • base64Encode
  • base64Decode

When a non-existent function is referenced, no error is shown in the logs and the request continues as normal.

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions