Ember CLI Deploy CloudFront Cache Invalidation
raw JSON →`ember-cli-deploy-cloudfront` is an `ember-cli-deploy` plugin designed to automate the invalidation of cached files on AWS CloudFront distributions as part of an Ember application's continuous deployment pipeline. The current stable version is 6.0.0, which notably updates the underlying AWS SDK to v3. The package's release cadence is tied to Node.js LTS support and critical dependency upgrades, such as the AWS SDK. Its primary use case is invalidating `index.html` after a new deployment, though it supports invalidating multiple custom paths and multiple CloudFront distributions. It differentiates itself by providing seamless integration into the `ember-cli-deploy` ecosystem, allowing developers to manage CloudFront cache busts directly from their Ember CLI projects without manual AWS console intervention. It supports various AWS authentication methods, including access keys, IAM roles, and profiles.
Common errors
error Missing credentials in config, if using profile make sure region is defined ↓
accessKeyId and secretAccessKey are set in config/deploy.js, or that a valid profile with an associated region is configured in ~/.aws/credentials, or that environment variables like AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are present and accessible. error InvalidationBatch contains 0 items ↓
objectPaths in config/deploy.js is correctly configured with valid paths (e.g., ['/index.html', '/assets/*']). Remember that all object paths must be relative to the CloudFront distribution root and begin with /. error The CloudFront distribution was not found. (DistributionIdNotFound) ↓
distribution ID in your config/deploy.js against your AWS CloudFront console to ensure it is accurate and belongs to the correct AWS account/region. error User: arn:aws:iam::... is not authorized to perform: cloudfront:CreateInvalidation on resource: arn:aws:cloudfront::.../distribution/... ↓
cloudfront:CreateInvalidation permission to the IAM user or role whose credentials are being used by the ember-cli-deploy-cloudfront plugin in your AWS IAM console. Warnings
breaking Minimum Node.js version has been progressively increased across major versions. `ember-cli-deploy-cloudfront@6.x` requires Node.js `16.* || 18.* || >= 20`. Earlier versions of the plugin dropped support for Node 6 (v2), Node 8 (v3), Node 10 (v4), and Node 12 (v5). ↓
breaking `ember-cli-deploy-cloudfront@6.0.0` upgraded the underlying AWS SDK from v2 to v3. This introduces breaking changes in the SDK's API, which will affect any custom `invalidationClient` implementations or direct interactions with the SDK. ↓
gotcha AWS credentials (e.g., `accessKeyId`, `secretAccessKey`, `profile`) are resolved by the AWS SDK in a specific order. Explicitly setting `accessKeyId` and `secretAccessKey` directly in `config/deploy.js` will override environment variables or profile settings, which might lead to unexpected behavior. ↓
Install
npm install ember-cli-deploy-cloudfront yarn add ember-cli-deploy-cloudfront pnpm add ember-cli-deploy-cloudfront Imports
- CloudFrontClient wrong
const { CloudFront } = require('aws-sdk');correctimport { CloudFrontClient } from '@aws-sdk/client-cloudfront'; - CreateInvalidationCommand wrong
const CreateInvalidationCommand = require('aws-sdk/clients/cloudfront').CreateInvalidationCommand;correctimport { CreateInvalidationCommand } from '@aws-sdk/client-cloudfront'; - CloudFrontClientConfig
import { CloudFrontClientConfig } from '@aws-sdk/client-cloudfront';
Quickstart
/* config/deploy.js */
module.exports = function(deployTarget) {
const ENV = {
build: {
environment: deployTarget
},
'cdn-url': {
// Example for a paired s3-index plugin, typically used with cloudfront
url: process.env.CDN_URL || 'https://your-cloudfront-distribution-domain.com'
},
cloudfront: {
// Recommended: use environment variables for sensitive credentials
accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '',
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '',
distribution: process.env.CLOUDFRONT_DISTRIBUTION_ID ?? '', // REQUIRED: Your CloudFront Distribution ID
region: process.env.AWS_REGION ?? 'us-east-1', // Specify your AWS region
objectPaths: ['/index.html', '/assets/*'], // Paths to invalidate. Must start with '/'
waitForInvalidation: true // Wait for the invalidation to complete (introduced in v2.0.0)
}
};
// Add additional deploy target specific configuration here
if (deployTarget === 'production') {
// Specific production settings
}
return ENV;
};
// To install:
// ember install ember-cli-deploy-cloudfront
// To run deployment with activation:
// AWS_ACCESS_KEY_ID='YOUR_KEY' AWS_SECRET_ACCESS_KEY='YOUR_SECRET' CLOUDFRONT_DISTRIBUTION_ID='E123ABCDEFGH' ember deploy production --activate