I am using AWS SAM CLI
According to https://aws.amazon.com/about-aws/whats-new/2020/07/cloudfront-geolocation-headers/ geolocation is already supported and CloudFront returns with the geolocation headers; example:
CloudFront-Viewer-Country-Name: United States
CloudFront-Viewer-Country-Region: MI
CloudFront-Viewer-Country-Region-Name: Michigan
CloudFront-Viewer-City: Ann Arbor
CloudFront-Viewer-Postal-Code: 48105
CloudFront-Viewer-Time-Zone: America/Detroit
CloudFront-Viewer-Latitude: 42.30680
CloudFront-Viewer-Longitude: -83.70590
CloudFront-Viewer-Metro-Code: 505
I want to be able to access these using my API gateway rest API here's a sample of my aws sam template.
Resources:
login:
Type: AWS::Serverless::Function
Properties:
Handler: src/functions/login.handler
Runtime: nodejs14.x
Layers:
- !Ref dependencies
Events:
ApiEvent:
Type: Api
Properties:
Method: post
Path: /login
RestApiId:
Ref: mainBackendApi
mainBackendApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Stage
EndpointConfiguration:
Type: EDGE
Domain:
DomainName: !Sub
- <hidden>
- apiSubDomain: !FindInMap
- stageVars
- !Ref Stage
- apiSubDomain
CertificateArn: !Ref customDomainCert
Route53:
HostedZoneId: <hidden>
So far, I have been researching for 5 hours now and haven't found any actual solution so I have no choice but to ask here. Hopefully someone can help me out.
I asked this question here https://github.com/aws/aws-sam-cli/issues/2498 as well but I was turned down.