我正在构建的某些功能中有一个非常奇怪的行为。
我在我正在构建的系统上使用 aws Cognito 进行用户管理。创建帐户时,cognito 会向用户发送一封电子邮件邀请,其中包含一次性用户代码。 我想用 base64 编码这个代码。
这是一个示例块
#get the value from the event Cognito sends
value = event["request"]["codeParameter"]
#encode it with base64
value_bytes = value.encode('ascii')
base64_bytes = base64.b64encode(value_bytes)
base64_string = base64_bytes.decode('ascii')
logging.info = ("base 64 string : %s", base64_string)
接下来发生的是 - 该值用 HTML 编写并作为电子邮件发送。 如果我跳过 Base64 编码 - 一切正常。 但是,如果我进行 Base 64 编码,则解码值始终为 {####} - 我假设被 cognito / aws 屏蔽。 该代码块在 aws-lambda 范围之外的本地计算机上工作得很好,但在 aws 上永远无法工作,并且无论接收到哪个代码(随机生成),我在 Base 64 解码后都会得到相同的输出,即 - {#### }
如果我尝试,也会发生同样的事情:
有什么想法导致这种行为吗?
似乎在 AWS Lambda 环境中使用 Base64 对 Cognito 用户邀请代码进行编码时,解码后的值始终是 {####}。本地不会出现此问题。
故障排除:
Did you try?
将代码包装在 try- except 块中以进行错误处理并检查任何异常。这应该有助于确定问题的根源。