AWS Lambda function for URL masking

0

I have a vanity URL that I want to redirect to a specific page in a website(Cloudfront Distribution). I can do a redirect with Masking from GoDaddy but it does not help me with https options for the vanity URL. So I was thinking of doing this using Lambda function triggered on Viewer Request section of the CF distribution. I am using the following code for the Lambda function, can anyone let me know what I am doing wrong as I am getting an error from CF side-

import json

def lambda_handler(event, context):
  request = event['Records'][0]['cf']['request']
  response = {
    'status': '301',
    'statusDescription': 'Moved Permanently',
    'headers': {
        'location': [{
            'key': 'Location',
            'value': 'https://cf-distribution/page/'
        }]
      }
   }
  return response
1개 답변
0

Hi Deep,

Without sharing the exact error you're getting from CloudFront it isn't easy to help you, but I will share with you the following links that are a good reference for what you're trying to build:

Also, it's important to remember that AWS Lambda@Edge functions must be deployed in the N. Virginia (us-east-1) region.

Let me know if that helped you and if not, please comment by adding the exact errors you mention you're getting from CloudFront so we can help you further.

If the answer is helpful, please click "Accept Answer" and upvote it.

profile picture
전문가
답변함 8달 전
  • this is the error i get -

    403 ERROR The request could not be satisfied. Bad request. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner. If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

    Generated by cloudfront (CloudFront) Request ID: xULrJ-FAUMug9oooA3rES-fH-2EooWXhuuHZt3uiUvuGbLOY571G-g==

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

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

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

관련 콘텐츠