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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ