- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试通过 Lambda 函数(通过无服务器构建)发回 JSON 响应,但出现错误。
我正在创建响应:
response = {}
response["file_name"] = file_name
response["status"] = status
response["description"] = message
response["data"] = data
return {
"isBase64Encoded": False,
"statusCode": 200,
"headers": {
"Content-Type": "application/json",
},
"body": json.dumps(response)
}
但 AWS 仅返回:
{
"message": "Internal server error"
}
我正在打印该响应对象,它是:
{'isBase64Encoded': False, 'statusCode': 200, 'headers': {'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json'}, 'body': '{"file_name": "upload-4660557513950187006.csv", "status": "success", "description": "Success.", "data": ""}'}
当我通过 API Gateway 调用时,这是我收到的日志:
Thu Oct 05 16:21:15 UTC 2017 : Endpoint request body after transformations: {"resource":"/parse","path":"/parse","httpMethod":"POST","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"path":"/parse","accountId":"317910044022","resourceId":"xik9xe","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"317910044022","cognitoIdentityId":null,"caller":"AIDAJGNM4CLIWDKHDDV2U","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"ASIAJHGYEQDHKLLRWL6A","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::317910044022:user/chase","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_131)","user":"AIDAJGNM4CLIWDKHDDV2U"},"resourcePath":"/parse","httpMethod":"POST","apiId":"3gvwsa0cj2"},"body":"{\n\t\"file_name\": \"upload-4660557513950187006.csv\",\n\t\"vendor\": \"\"\n}","isBase64Encoded":false}
Thu Oct 05 16:21:15 UTC 2017 : Sending request to https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-east-1:317910044022:function:PyParsingService-dev-parse/invocations
Thu Oct 05 16:21:16 UTC 2017 : Received response. Integration latency: 416 ms
Thu Oct 05 16:21:16 UTC 2017 : Endpoint response body before transformations: "{\"isBase64Encoded\": false, \"statusCode\": 200, \"headers\": {\"Access-Control-Allow-Origin\": \"*\", \"Content-Type\": \"application/json\"}, \"body\": \"{\\\"file_name\\\": \\\"upload-4660557513950187006.csv\\\", \\\"status\\\": \\\"success\\\", \\\"description\\\": \\\"Success.\\\", \\\"data\\\": \\\"\\\"}\"}"
Thu Oct 05 16:21:16 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=36059915-a9e9-11e7-8444-438990db7407, Connection=keep-alive, Content-Length=317, Date=Thu, 05 Oct 2017 16:21:15 GMT, X-Amzn-Trace-Id=root=1-59d65bfb-7000702549081b6682b894a9;sampled=0, Content-Type=application/json}
Thu Oct 05 16:21:16 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response
Thu Oct 05 16:21:16 UTC 2017 : Method completed with status: 502
对 Python 不太有经验 - 任何帮助将不胜感激。根据this响应需要针对 API 网关进行正确格式化。不确定为什么我的响应不符合 API Gateway 的要求。
最佳答案
我发现我做错了什么。 由于配置错误而执行失败:格式错误的 Lambda 代理响应错误引用了 Lambda 尝试通过 API Gateway 发回的响应。无服务器自动使用 Lambda 代理集成。当我查看响应时,我注意到基本响应级别有额外的转义(例如, "{\"isBase64Encoded\": false,\"statusCode\": 200, ...}
),我相信这触发了错误。果然,当我深入研究时,我意识到我在创建响应后转储 JSON (json.dumps()
),这引发了错误.
感谢您的回复。我的无意识错误。
关于python - Lambda 代理响应格式错误 : deploying python endpoints through serverless,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46577881/
在我的 serverless.yml 中,我使用 serverless-tscpaths 插件来解析 tsconfig 中定义的路径,并使用 serverless-plugin-optimize 来缩
我阅读了这个文档:https://serverless.com/framework/docs/providers/google/guide/services/ users/ serverless.
使用 Serverless framework ,我希望能够从环境变量更改 AWS 区域。 provider: name: aws region: ${env:AWS_REGION} 然后,A
我想开始使用无服务器框架来管理我公司的 lambda 部署,但我们处理 PHI 的安全性非常严格。我们的合规总监和 CTO 担心将我们的 AWS key 和 secret 传递给另一家公司。 当做 s
这是我的 serverless.yml 文件中的一个片段: Resources: LogGroupInfo: Type: 'AWS::Logs::LogGroup' Propert
我正在使用 AWS Aurora serverless 设置一个新数据库,并且需要启用 binlog。我想我已经按原样遵循了文档,但无法使其正常工作。我该如何设置? 按照文档,以下是我尝试启用 bin
我不想在 serverless.yml 中手动定义服务名称,而是想从 package.json 中读取 name 最佳答案 为了实现基于 package.json 应用程序名称的动态服务名称,我利用了
我将以下内容用作自定义 serverless-dotenv-plugin 插件配置: 风俗: dotenv: 路径:.env-${opt:stage, 'local'} 但我真正想得到的是当我不提供任
我正在使用无服务器模板并且一切正常,直到突然我的所有部署开始忽略 .env文件。 我搜索了documentation它说如果我想使用 .env 文件中的环境变量,我现在必须添加 useDotenv:
我正在使用新的无服务器 TypeScript monorepo 启动一个新项目!用过 aws-nodejs-typescript模板,它给出了 serverless.ts配置文件。几周后,我现在在命令
https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/ provider: stackTags:
各位 我正在尝试设置我的第一个 NestJS 应用程序。它由 AWS 上的无服务器提供支持。 我创建了一个简单的 Controller ,它有一个服务作为依赖项。当我使用 HTTP 客户端访问端点时,
AWS::Serverless::Api 和 AWS::Serverless::HttpApi 之间有什么区别? 据我了解,AWS::Serverless::HttpApi 似乎配置了 HTTP AP
我正在尝试使用 serverless.yml 替换 @vendia/serverless-express v2 示例中的默认 sam-template,以便通过无服务器部署进行部署 https://g
I am new to using serverless framework ,I wanted to create three different environments dev,Qa,pr
我希望向本地运行的无服务器框架 Node 应用程序添加状态。我遇到了官方的 DynamoDb docker 镜像,我想使用无服务器框架以及在 localhost:8000 公开的 docker 上运行
我有一个 AWS CodeBuild 项目,它尝试安装无服务器框架,但在标题中返回错误,但它说框架已成功安装。我的理解是这无法安装 snappy 模块。为什么会这样?我该如何解决? 我在 builds
无服务器是云原生的子集或属性吗?或者是另一种方式——云原生是无服务器的子集或属性吗? Nathan Aw(新加坡) 最佳答案 云原生 是一种更通用的方法来构建和运行利用云计算的应用程序。 无服务器 更
Serverless 架构演进 Serverless架构风格挑战了软件设计和软件部署基础的现状,以实现最佳开发、最优运营和最优的管理开销。虽然它继承了微服务架构MSA的基本概念,但它已被赋予了新的
前言 当您第一次接触 Serverless 的时候,有一个不那么明显的新使用方式:与传统的基于服务器的方法相比,Serverless 服务平台可以使您的应用快速水平扩展,并行处理的工作更加有效。这
我是一名优秀的程序员,十分优秀!