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 Respuesta
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
EXPERTO
respondido hace un año

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas