Search code examples
openwhisk

How to return non 200 HTTP status codes with Serverless + OpenWhisk and behind IBM Cloud API Gateway?


I can't figure out how to return http status codes for functions behind an API GW. No matter what I return, it always comes back as a 200. I've tried statusCode and code to no avail.

I'm using the Serverless framework with the OpenWhisk plugin. I'm deploying to IBM Cloud.


Solution

  • Web Action response content type parameter must be set to http to manually configure the HTTP response. This value defaults to json which ignores returned headers and statusCode values.

    In The Serverless Framework, this value is set in the event configuration section of your YAML.

    functions:
      my_function:
        handler: index.main
        events:
          - http:
              method: GET
              path: /api/greeting
              resp: http