Reputation: 1502
I'm wondering if I could configure my API Gateway and Lambda function to handle incoming connections from a CNAME. Consider the following:
example.com
which has a CNAME set to api.mydomain.com
api.mydomain.com
has a Custom Domain Mapping in API Gatewayexample.com
)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
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
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