ddibiase
ddibiase

Reputation: 1502

Using API Gateway/Lambda function to handle CNAME requests from various domains

I'm wondering if I could configure my API Gateway and Lambda function to handle incoming connections from a CNAME. Consider the following:

What I'm trying to do is use the Lambda as a way to interpret requests from other domains so that I don't have to manually configure the mappings.

Upvotes: 0

Views: 484

Answers (2)

Michael - sqlbot
Michael - sqlbot

Reputation: 179114

so that I don't have to manually configure the mappings

This can't be avoided. Unless API Gateway has a custom domain mapping configured the hostname found in the HTTP Host header and TLS SNI -- which will be example.com in this case -- your request will arrive at a pool of AWS servers that do not know how to handle it, because you haven't configured it, and it will not invoke the Lambda function.

Additionally, you'll need a matching SSL certificate attached to the API Gateway custom domain.

Upvotes: 0

Tuan Vo
Tuan Vo

Reputation: 2065

You can get domainName from requestContext

Create lambda below, Add API gateway.

Then you can find out useful information you want.

import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps(event["requestContext"]["domainName"])
    }

Upvotes: 1

Related Questions