没有专门集成 API 网关和 Codebuild 的实际指南,因此我正在研究几个并尝试适应。
我已根据此文档设置了我的角色和策略,并且我的 CodeBuild 项目已设置并成功运行。
我已经设置了一个 POST 端点,参考 CodeBuild API 文档中的操作:
我正在使用端点的测试选项卡来发送
{ "project": "my-project" }
但是我收到了这个回复
{
"Output": {
"__type": "com.amazon.coral.service#UnknownOperationException",
"message": null
},
"Version": "1.0"
}
日志
Execution log for request b0ee0d54-c1d0-11e9-9ff3-e9448aaf711c
Sun Aug 18 15:56:07 UTC 2019 : Starting execution for request: b0ee0d54-c1d0-11e9-9ff3-e9448aaf711c
Sun Aug 18 15:56:07 UTC 2019 : HTTP Method: POST, Resource Path: /vegankit/stage
Sun Aug 18 15:56:07 UTC 2019 : Method request path: {}
Sun Aug 18 15:56:07 UTC 2019 : Method request query string: {}
Sun Aug 18 15:56:07 UTC 2019 : Method request headers: {}
Sun Aug 18 15:56:07 UTC 2019 : Method request body before transformations: { "project": "stage-vegankit-com" }
Sun Aug 18 15:56:07 UTC 2019 : Endpoint request URI: https://codebuild.us-east-1.amazonaws.com/?Action=StartBuild
Sun Aug 18 15:56:07 UTC 2019 : Endpoint request headers: {Authorization=****************************************************************************************************************************************************************************************************************************************************************************388440, X-Amz-Date=20190818T155607Z, x-amzn-apigateway-api-id=[redacted], Accept=application/json, User-Agent=AmazonAPIGateway_[redacted], X-Amz-Security-Token=[redacted] [TRUNCATED]
Sun Aug 18 15:56:07 UTC 2019 : Endpoint request body after transformations: { "project": "my-project" }
Sun Aug 18 15:56:07 UTC 2019 : Sending request to https://codebuild.us-east-1.amazonaws.com/?Action=StartBuild
Sun Aug 18 15:56:08 UTC 2019 : Received response. Status: 200, Integration latency: 360 ms
Sun Aug 18 15:56:08 UTC 2019 : Endpoint response headers: {x-amzn-RequestId=7afcfc90-de3e-424a-b7d9-b47ff926c1d0, Content-Type=application/json, Content-Length=105, Date=Sun, 18 Aug 2019 15:56:08 GMT}
Sun Aug 18 15:56:08 UTC 2019 : Endpoint response body before transformations: {"Output":{"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}
Sun Aug 18 15:56:08 UTC 2019 : Method response body after transformations: {"Output":{"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}
Sun Aug 18 15:56:08 UTC 2019 : Method response headers: {X-Amzn-Trace-Id=Root=[redacted], Content-Type=application/json}
Sun Aug 18 15:56:08 UTC 2019 : Successfully completed execution
Sun Aug 18 15:56:08 UTC 2019 : Method completed with status: 200
在 HTTP Headers 中,您应该定义这两个标头:
Content-Type = 'application/x-amz-json-1.1'
X-Amz-Target = 'CodeBuild_20161006.StartBuild'
起初我只添加了 X-Amz-Target,但我继续收到相同的错误,后来我在 github 问题中发现有人还将具有该值的 Content-Type 传递给请求,我尝试并工作了。
我希望这对未来的其他人有帮助。
我的问题是我使用了不受支持的action的名称。我将操作设置为 StartExecution 并且它有效。
来源:https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html
这是因为Content-Type标头丢失了
添加标题
如果使用 POST 请求发送数据则: Content-Type: 'application/x-www-form-urlencoded'
Content-Type: '您的请求内容类型'