我是 aws 开发新手,尝试使用 aws cognito 的自定义身份验证流程、lambda 触发器和 aws python SDK 来实现无密码功能。
我的问题是在调用InitiateAuth之后,我总是收到以下错误:
An error occurred (InvalidLambdaResponseException) when calling the InitiateAuth operation: Unrecognizable lambda output
完整的回溯是:
Traceback (most recent call last):
File "test_custom_auth.py", line 52, in <module>
ClientId=client_id
File "/Users/jules/Repositories/snaaap/onemac-api/env/lib/python3.6/site-packages/botocore/client.py", line 320, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/jules/Repositories/snaaap/onemac-api/env/lib/python3.6/site-packages/botocore/client.py", line 623, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidLambdaResponseException: An error occurred (InvalidLambdaResponseException) when calling the InitiateAuth operation: Unrecognizable lambda output
我可以通过 cloudwatch 日志看到 defineAuthChallenge Trigger 和 createAuthChallenge Trigger 调用成功,甚至能够打印日志来验证这一点。
我首先使用 Javascript 执行 lambda 函数,然后使用 Python,只是为了尝试另一种方法。
我尝试在 python 中返回以下内容(我正在使用 lambda 编辑器控制台进行编辑)
-
return event
-
result = { "isBase64Encoded": False, "statusCode": 200, "headers": {}, "body": json.dumps(event) } return result
我尝试在 javascript 中返回以下内容(我正在使用 lambda 编辑器控制台进行编辑)
-
context.succeed(event)
-
callback(null, event)
-
context.done(event)
-
context.done(JSON.stringify(event))
以及上面提到的排列,但我仍然不断收到错误:(感谢任何可以提供帮助的人!
编辑
执行了另一个请求:
以下是来自 defineAuthChallenge 的日志:
START RequestId: 14441740-cc65-11e8-a632-9508cbba464c Version: $LATEST
END RequestId: 14441740-cc65-11e8-a632-9508cbba464c
REPORT RequestId: 14441740-cc65-11e8-a632-9508cbba464c Duration: 6.70 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 20 MB
以下是来自 **createAuthChallenge ** 的日志:
START RequestId: 144995b6-cc65-11e8-8d2d-5388c84ccf95 Version: $LATEST
END RequestId: 144995b6-cc65-11e8-8d2d-5388c84ccf95
REPORT RequestId: 144995b6-cc65-11e8-8d2d-5388c84ccf95 Duration: 592.59 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 29 MB
最佳答案
在我从 createAuthChallenge 函数返回的响应中,将 challengeMetaData
更改为 challengeMetadata
。据了解,当您在响应属性中放入无效 key 时,lambda 将抛出 InvalidLambdaResponseException
,不过我希望下次 cloudwatch 能够捕获它。
从 @thomasmichaelwallace 得到了一个想法,这篇文章 https://forums.aws.amazon.com/thread.jspa?threadID=237677 .
关于javascript - 调用InitiateAuth操作时发生错误(InvalidLambdaResponseException): Unrecognizable lambda output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52735509/