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 個回答
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
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南