6

There's no actual guide to integrating specifically API gateway and Codebuild, so I'm looking at several and trying to adapt.

I have my roles and policies set up per this documentation and have my CodeBuild project setup and running successfully.

I've set up a POST endpoint as such, referring to the actions from the CodeBuild API documentation:

enter image description here

And I am using the test tab for the endpoint to send

{ "project": "my-project" }

but am getting this response

{
  "Output": {
    "__type": "com.amazon.coral.service#UnknownOperationException",
    "message": null
  },
  "Version": "1.0"
}

Logs

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
Adam Grant
  • 12,477
  • 10
  • 58
  • 65
  • 1
    I am also getting same error in using cognito proxy on api gateway "com.amazon.coral.service#UnknownOperationException" - Any luck or update ? – Abdeali Chandanwala Aug 19 '20 at 10:20

3 Answers3

13

In HTTP Headers, you should define these two headers:

Content-Type = 'application/x-amz-json-1.1'
X-Amz-Target = 'CodeBuild_20161006.StartBuild'

At first I only added X-Amz-Target but I continue to get the same error and later I found in github issue that someone was passing also Content-Type with that value to the request and I tried and worked.

I hope this helps others in the future.

Emma
  • 27,428
  • 11
  • 44
  • 69
Yunior Alayo
  • 139
  • 1
  • 5
0

The problem in my case was that I used an unsupported action's name. I set the action to StartExecution and it works.

enter image description here

Source: https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html

Ilyas
  • 1,976
  • 15
  • 9
0

It is because Content-Type header is missing

add header
If using POST request to send data then: Content-Type: 'application/x-www-form-urlencoded'
Content-Type: 'your request content type'

VipulVyas
  • 41
  • 4