编码和解码 base64.in aws appsync 解析器

encoding and decoding base64.in aws appsync resolver

我有一个接收参数“nextToken”($ctx.args.nextToken) 的解析器,该参数将在 base64 字符串中。在请求映射模板中,我需要将 nextToken 从 base64 字符串转换为 ascii 字符串。我知道 Appsync 有 $util.base64Decode(String) : byte[] 但这个函数返回 byte[] 但我想要一个 ascii 字符串。

此外,我需要在响应映射模板中从 ascii 字符串创建 base64 字符串。 Appsync 再次提供函数 $util.base64Encode( byte[] ) : String 但我不知道如何将我的 ascii 字符串更改为 byte[].

任何人都知道如何处理这两种情况。提前致谢。

用于 base64 的 VTL 模板 $util 函数接受字符串和 return 字符串。

示例 VTL 模板:

#set($base64 = $util.base64Encode("Hello World"))
{
  "label": "$util.base64Decode($base64)"
}

Returns“你好世界”