Allow AWS API Gateway to return YAML format, when a specific JSON property equals YAML

15 views Asked by At

I have a .net6.0 AWS Lambda function that takes in a JSON object and does a specific task that returns an object named "response". the lambda function is connected to an API Gateway as well. By default, the API Gateway returns the response object in JSON format.

Recently I added a new property to the JSON Object(that is initially passed into the lambda function) named "OutputType". This property determines what format the response object should be returned to the client. Initially, I was converting the object into YAML in the actual lambda function by doing the following:

var serializer = new SerializerBuilder().Build()
var yaml = serializer.Serialize(response)

The problem with this approach is that the API Gateway returns the yaml variable as a string inside of a JSON Object. What I want is for the API Gateway to return the response object in actual YAML format when the JSON Property "OutputType" = "YAML".

Does anyone know how to solve this issue, I have been stuck on this for a few days now. Any help is welcome!

Thank You!

0

There are 0 answers