简体   繁体   English

测试 aws lambda python function 嵌套 json

[英]Testing aws lambda python function with nested json

Below is what I would like to input as my testing event and is what my lambda python function knows how to process.以下是我想作为我的测试事件输入的内容,也是我的 lambda python function 知道如何处理的内容。

{
  "body": '{"email":"example@example.com","password":"Example1"}',
  "path": "/SignIn"
}

However, you can't configure this as a testing event in aws lambda because you get the following–somewhat justified–error:但是,您不能将此配置为 aws lambda 中的测试事件,因为您会收到以下(有点合理)错误:

There is an error in your JSON event. Please correct it before saving.

It is somewhat justified because there shouldn't be any single quotes in JSON. However, it won't work if I use all double quotes either.有点道理,因为JSON不应该有任何单引号。但是,如果我使用所有双引号也不行。

Any ideas?有任何想法吗? Loopholes?漏洞?

You can do something like this你可以这样做

{
  "body": "{\"email\":\"example@example.com\",\"password\":\"Example1\"}",
  "path": "SignIn"
}

But then do json.loads() and get rid of the "", but ideally I will never send a password on API payload like this!但是然后执行 json.loads() 并去掉“”,但理想情况下我永远不会像这样在 API 有效负载上发送密码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM