Tomás Larrain
Tomás Larrain

Reputation: 125

Unsupported media type when calling API Gateway from step function

I have the following sample step function where I call one endpoint, and then a second one using the status text from the first response as a parameter:

{
  "Comment": "A Hello World example of the Amazon States Language using Pass states",
  "StartAt": "Api Call",
  "States": {
    "Api Call": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "***********.us-east-1.amazonaws.com",
        "Method": "GET",
        "Path": "universities",
        "RequestBody": {},
        "AuthType": "NO_AUTH"
      },
      "ResultSelector": {
        "logWord.$": "$.StatusText"
      },
      "Next": "Api Call 2"
    },
    "Api Call 2": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "***********.us-east-1.amazonaws.com",
        "Method": "POST",
        "Path": "postLogging",
        "RequestBody": {
          "logWord.$": "$.logWord"
        },
        "AuthType": "NO_AUTH"
      },
      "End": true
    }
  }
}

The error that the step function is showing is the following:

{
  "resourceType": "apigateway",
  "resource": "invoke",
  "error": "ApiGateway.415",
  "cause": {
    "timestamp": "2022-01-28T14:54:44.033+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "path": "/postLogging"
  }
}

Any idea what could be happening? I'm trying to log more details from the gateway but I can't put the content type or the request body on them. Any guidance is welcomed. Thanks!

Upvotes: 0

Views: 668

Answers (1)

Tomás Larrain
Tomás Larrain

Reputation: 125

I just find a solution. If I add a header with content-type, it works:

{
  "Comment": "A Hello World example of the Amazon States Language using Pass states",
  "StartAt": "Api Call",
  "States": {
    "Api Call": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "***********.us-east-1.amazonaws.com",
        "Method": "GET",
        "Path": "universities",
        "RequestBody": {},
        "AuthType": "NO_AUTH"
      },
      "ResultSelector": {
        "logWord.$": "$.StatusText"
      },
      "Next": "Api Call 2"
    },
    "Api Call 2": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "***********.us-east-1.amazonaws.com",
        "Method": "POST",
        "Path": "postLogging",
        "RequestBody": {
          "logWord.$": "$.logWord"
        },
        "Headers": { 
            "Content-Type": ["application/json"] 
        },
        "AuthType": "NO_AUTH"
      },
      "End": true
    }
  }
}

Upvotes: 1

Related Questions