Deploying to AWS with S3 and CloudFront
This deployment example refers to AWS static hosting using an S3 bucket and CloudFront distribution.
Prerequisites
Before you get started, you need to have:
- An AWS account.
- A commercetools account and a Project.
- A Custom Application configured in the Merchant Center.
Configuration
In your Custom Application config, provide the Custom Application ID you got when you configured the Custom Application in the Merchant Center.
Moreover, you need to provide the production URL from your CloudFront site. You can keep the standard CloudFront URL https://<site>.cloudfront.net
or provide your custom domain.
{"env": {"production": {"applicationId": "ckvtahxl90097sys6har1e6n3","url": "https://<site>.cloudfront.net"}}}
Using environment variables
In case you want to avoid hardcoding certain values, for example the Application ID, or the Project key, you can use variable placeholders in your Custom Application config.
{"env": {"production": {"applicationId": "${env:APPLICATION_ID}","url": "https://<site>.cloudfront.net"}}}
Set up S3 and CloudFront
To host the production bundles of your Custom Application you need to create some resources in AWS, like an S3 bucket, configure a CloudFront distribution, etc.
A Custom Application 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
.
See Going to production for more information.
Test your deployment
In the Merchant Center you can now follow the steps to install the Custom Application and access it in your Projects.
The Custom Application won't render if you try to access it directly via the deployment URL, as it needs to be served within the Merchant Center Proxy Router.
Therefore, Preview deployments are not really useful. If you are interested in this functionality, let us know and open a support issue.