Solo
Solo

Reputation: 6977

How to only add header if value is present?

My Lambda function returns {data: {...}} body to API Gateway but it can also return {data: {...}, cookie: ...} if user is logging in.

I added Header Mapping to API Gateway that adds that cookie value to header:

Set-Cookie: integration.response.body.cookie

Now I end up with empty set-cookie headers if response body has no cookie. This point also applies to every other header added via Header Mapping.


Is there a way to set header only when value in response body is present?

Upvotes: 0

Views: 568

Answers (1)

Kenneth Rory Dunn
Kenneth Rory Dunn

Reputation: 876

Lambda Proxy Integrations will afford you the dynamic control of response headers you require.

Your Lambda function will need to return the entire HTTP response, including status code, body and headers.

http://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format

Currently there is no way to dynamically map headers other than to use Proxy Integrations.

Upvotes: 1

Related Questions