CloudFront

Get started with AWS CloudFront on LocalStack

LocalStack Pro supports creation of local CloudFront distributions, which allows you to transparently access your applications and file artifacts via CloudFront URLs like https://abc123.cloudfront.net.

For example, take the following simple example which creates an S3 bucket, puts a small text file hello.txt to the bucket, and then creates a CloudFront distribution which makes the file accessible via a https://abc123.cloudfront.net/hello.txt proxy URL (where abc123 is a placeholder for the real distribution ID):

$ awslocal s3 mb s3://abc123
$ echo 'Hello World' > /tmp/hello.txt
$ awslocal s3 cp /tmp/hello.txt s3://abc123/hello.txt --acl public-read
$ domain=$(awslocal cloudfront create-distribution \
   --origin-domain-name abc123.s3.amazonaws.com | jq -r '.Distribution.DomainName')
$ curl -k https://$domain/hello.txt

Using custom URLs

LocalStack Pro supports the use of an alternate domain name, also known as a CNAME or as a custom domain name, to access your applications and file artifacts instead of using the domain name that CloudFront generates for your distribution.

To do so, the custom domain name must be set up in your local DNS server first. You can further add the desired domain name as an alias for the target distribution. To achieve this, you will need to provide the Aliases field in the --distribution-config option while creating or updating a distribution. The format of this structure is similar to what is used in AWS CloudFront options.

The following example shows two domains being specified as Aliases for a distribution. Please consider that a full configuration would require other values relevant to the distribution beside these shown in this example. They were omited here for brevity.

--distribution-config {...'Aliases':'{'Quantity':2, 'Items': ['custom.domain.one', 'customDomain.two']}'...}