简体   繁体   中英

Returning header content - API Gateway + AWS Lambda

I am developing a POST lambda function. I want to return "Location" in the header. So I configure API Gateway, like below:

API网关配置

when I call the API, I am receving the "Location" correct in the header, but I am still receiving it on return message. Look below:

[ 返回地点[2]

My python code:

def os_create_subscription (event, context):
    customer_id = event["customer-id"]
    subscription_id = 12345
    header_location = ("/customers/%s/subscriptions/%d" % (customer_id, subscription_id))
    result = {"Location": header_location}
    return result

So i would like to have the Location just in the header. Is there anyway to do this?

Header mapping from response bodies was a recently added to API Gateway. You can see examples in our documentation .

Your mapping should be: integration.response.body.Location

Edit: Apologies for misreading. To remove the Location from the response body, you would need to have a mapping template with an empty JSON body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM