Load Balancer host based on User's CloudFront-Viewer-Country

0

We have a Cloudfront distribution whose origin is set to an application load balancer(by default). We want to set this load balancer host based on user's CloudFront-Viewer-Country. Below is the lambda that we're using to do the redirection eu_lb = "EU_LB_HOST" ap_lb = "AP_LB_HOST"

def lambda_handler(event, context): request = event['Records'][0]['cf']['request']

viewer_country = request['headers'].get('cloudfront-viewer-country')
if viewer_country:
    country_code = viewer_country[0]['value']
    if country_code == 'GB' or country_code == 'DE' or country_code == 'IE':
        domain_name = eu_lb
        request['origin']['custom']['domainName'] = domain_name
        request['headers']['host'] = [{'key': 'host', 'value': domain_name}]
return request

The issue is that we've setup a Route53 record to mask the url so let's say xyz.com is the url which points to Cloudfront host and from Cloudfront we want the request to go to load balancer but since there's a redirection at lambda@edge it changes the url to Load Balancer's host (xyz.com -> lb_host.com) We have some URL dependency at our code level which we cannot rectify as of now. Is there any way at Lambda@Edge level so that the URL doesn't change? Or is there any other solution to this? Kindly help us! Thanks in advance!

1개 답변
0

There is no redirection configured in your Lambda function - it's just changing the Origin and the host header used when CloudFront sends the request to the Origin. If the viewer is getting redirected to a different domain name, that must be happening somewhere else.

AWS
전문가
Paul_L
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠