How do I create a CloudFront distribution without an origin for a self-contained lambda@edge function?

Viewed 743

I have a small Node.js function on AWS Lambda that returns a very simple dynamic response, such as:

exports.handler = async (event, context) => {
    const response = {
        statusCode: 200,
        body: "Hello World " + Math.random(),
    };
    return response;
};

I want to deploy this on the public web through lambda@edge. To do this, I need to connect it to a CloudFront distribution. However, CloudFront requires that I choose an origin. This function doesn't need an origin.

Is it possible to deploy this without a CloudFront origin or do I need to create a dummy page, such as a static file on S3?

1 Answers

Don't create a dummy page. You can set an arbitrary domain name as the distribution origin.

If you use a function as a Viewer Request handler, you can set any domain name, for example dev.null.

If you use a function as an Origin Request handler, the domain name must be an existing valid name, for example example.com. As AWS support says, CloudFront performs a DNS validity check for the origin domain, but doesn't send requests to the domain (if the function returns a response).

Related