Daniil
Daniil

Reputation: 115

Can you redirect domains using AWS Lambda?

I am trying to redirect few domains to one with AWS Lambda

The logic is following:

  1. Hosted zone for domain example.eu with A record being Alias to an LB
  2. LB forwarding traffic to a Target Group and has a valid certificate
  3. Target is a Lambda function:
exports.handler = async (event) => {
    const response = {
        statusCode: 301,
        headers: {
            Location: 'https://example.com'
        }
    };
    
    return response;
};
  1. When I click on test and pass something to Lambda - it works and returning 301 but it is never getting triggered when I open example.eu in browser or using curl.

Expected result:

When I open example.eu it returns me 301 Moved Permanently https://example.com

Upvotes: 0

Views: 821

Answers (1)

Daniil
Daniil

Reputation: 115

As @Tobin pointed out - I had an issue with the security group. I've recreated the security group for 443 and 80 ports and it worked.

Upvotes: 1

Related Questions