Advanced Configuration
CloudFront Hosting Toolkit offers various advanced configuration options to tailor the deployment process to your specific needs. After running the init
command, you have the flexibility to customize your deployment before running the deploy
command.
Configuration Files
After running cloudfront-hosting-toolkit init
, three configuration files are created in your project’s cloudfront-hosting-toolkit
folder:
cloudfront-hosting-toolkit-config.yml
cloudfront-hosting-toolkit-cff.js
cloudfront-hosting-toolkit-config.json
You can edit these files to customize your deployment before running the deploy
command.
Customization Process
- Initial Setup: Run
cloudfront-hosting-toolkit init
to generate the default configuration files. - Customization: Edit the configuration files as needed (optional).
- Deployment: Run
cloudfront-hosting-toolkit deploy
to deploy your infrastructure using either the default or customized configuration.
Note: You can deploy using the default configuration and later customize as needed. After making changes to any configuration file, simply run the deploy
command again to update your infrastructure.
Custom Build Configurations
Modify the cloudfront-hosting-toolkit-config.yml
file to customize the build process. This file contains instructions for CodeBuild on how to build your website.
Example for a React app:
CloudFront Function Customization
The cloudfront-hosting-toolkit-cff.js
file contains the CloudFront Function code for URL rewriting. Modify this file to implement custom routing logic for your application.
Example of a basic URL rewriting function:
Project Configuration
The cloudfront-hosting-toolkit-config.json
file contains your project’s configuration settings. You can modify this file to change settings such as the repository URL, branch name, or framework.
Example:
Potential Modifications
Here are some examples of modifications you might make to each configuration file:
1. cloudfront-hosting-toolkit-config.yml
This file controls your build process. Some potential modifications include:
-
Changing the Node.js version:
-
Adding a testing step:
-
Customizing the artifact output:
2. cloudfront-hosting-toolkit-cff.js
This file contains your CloudFront Function for URL rewriting. You might modify it to:
-
Handle single-page application (SPA) routing:
-
Implement custom error page routing:
3. cloudfront-hosting-toolkit-config.json
This file contains your project configuration. Possible modifications include:
-
Changing the deployment branch:
-
Adding a custom domain:
Remember, you can always revert to the default configuration by re-running the init
command, but this will overwrite any existing customizations. Always backup your custom configurations before reinitializing.