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 Answer
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
EXPERT
answered 7 months ago
  • 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==

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions