Deploy to AWS with S3 and CloudFront

Learn how to deploy your customization to AWS static hosting using an S3 bucket and CloudFront distribution.

Prerequisites

Before you get started, you need to have:

Configuration

Adding the customization identifier and URL

Depending on the customization type, you'll need to specify either the Custom Application ID or the Custom View ID that was provided to you when you added the customization in the Merchant Center.

You'll also need to specify the production URL of your CloudFront site. You can keep the standard CloudFront URL https://<site>.cloudfront.net or provide your custom domain.

For Custom Applications, make the following changes to the Custom Application config:

custom-application-config.jsonjson
{
"env": {
"production": {
"applicationId": "ckvtahxl90097sys6har1e6n3",
"url": "https://<site>.cloudfront.net"
}
}
}

For Custom Views, make the following changes to the Custom View config:

custom-view-config.mjsJavaScript
const config = {
env: {
production: {
customViewId: 'ckvtahxl90097sys6har1e6n3',
url: 'https://<site>.cloudfront.net',
},
},
// ...
};

Using environment variables

To avoid hardcoding values (such as the customization identifier or the Project key), you can use variable placeholders in your Custom Application config or Custom View config.

Example of environment variables with Custom Applications:

custom-application-config.jsonjson
{
"env": {
"production": {
"applicationId": "${env:APPLICATION_ID}",
"url": "https://<site>.cloudfront.net"
}
}
}

Example of environment variables with Custom Views:

custom-view-config.mjsJavaScript
const config = {
env: {
production: {
customViewId: '${env:CUSTOM_VIEW_ID}',
url: 'https://<site>.cloudfront.net',
},
},
// ...
};

Set up S3 and CloudFront

To host the production bundles of your customization, you need to create some resources in AWS, like an S3 bucket, configure a CloudFront distribution, etc.

A customization is set up in a very similar way as a Create React App. Therefore, we recommend checking out other articles about configuring AWS for static hosting for more detailed explanations about the setup.

Production bundles

The main command to create the production bundles is mc-scripts build. The output folder is public.
For more information, see Going to production.

Test your deployment

Install your customization in the Merchant Center to access it within your Projects: