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 Resposta
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
ESPECIALISTA
respondido há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas