Registry / devops / serverless-cloudfront-invalidate

serverless-cloudfront-invalidate

JSON →
library1.12.2jsnpmunverified

Serverless Framework plugin that automatically invalidates CloudFront cache after deployment. Version 1.12.2 is the latest stable release, with updates as needed (not on a fixed cadence). Unlike manual AWS CLI commands or custom scripts, this plugin integrates directly into the Serverless deployment lifecycle, ensuring cache invalidation happens automatically after each `sls deploy`. It supports multiple distributions, stage-specific invalidation, and standalone invalidation via `sls cloudfrontInvalidate`. It is actively maintained with support for self-signed certificates and proxy configurations.

npm install serverless-cloudfront-invalidate
INSTALL
IMPORT
SIG · SERVERLESS-CLOUDFR
S
serverless-cloudfront-invalidate
devopsjavascriptv1.12.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

serverless-cloudfront-invalidate
plugins: - serverless-cloudfront-invalidate
plugins: - serverlessCloudfrontInvalidate
Common misspelling: the plugin key in serverless.yml must be the exact package name. Also must be listed as the last plugin.
Plugin
class MyPlugin extends Plugin { constructor() { super(); } }
const Plugin = require('serverless-cloudfront-invalidate');
The package is designed to be used declaratively in serverless.yml, not programmatically imported as a class. Direct require is not supported.

Minimal configuration to auto-invalidate CloudFront after each deploy.

// serverless.yml plugins: - serverless-cloudfront-invalidate # must be last custom: cloudfrontInvalidate: - distributionId: "CLOUDFRONT_DIST_ID" autoInvalidate: true items: - "/index.html" - "/static/*" # Or use distributionIdKey to reference a CloudFormation output: # distributionIdKey: "CDNDistributionId" provider: name: aws runtime: nodejs20.x stage: dev region: us-east-1 functions: hello: handler: handler.hello resources: Resources: CDN: Type: AWS::CloudFront::Distribution Properties: DistributionConfig: DefaultCacheBehavior: TargetOriginId: myOrigin ViewerProtocolPolicy: redirect-to-https ForwardedValues: QueryString: false Enabled: true Outputs: CDNDistributionId: Description: CloudFront Distribution ID Value: !Ref CDN
Debug
Known issues
gotchaPlugin must be listed as the last plugin in serverless.yml, otherwise it may not execute after all resources are deployed.
fix
Always place `serverless-cloudfront-invalidate` at the end of the plugins list.
affects: >=0.0.0
gotchaIf using `distributionIdKey`, the referenced CloudFormation output must exist and contain the distribution ID as a string. Using a Ref to a resource (e.g., Ref: CDN) outputs the distribution ID, but must be used as an Output.
fix
Ensure the CloudFormation Output is defined and outputs the Ref of the CDN resource. The plugin reads the output after stack creation.
affects: >=0.0.0
deprecatedAuto-invalidation is enabled by default, but some users may inadvertently invalidate production distributions on every deploy. The `autoInvalidate` option can be set to false to prevent automatic invalidation.
fix
Set `autoInvalidate: false` on the invalidation config for non-production stages or use stage-specific configurations.
affects: >=0.0.0
gotchaThe `items` list must include at least one path. Using an empty list or omitting the key will cause a validation error.
fix
Always provide at least one path in the `items` array (e.g., \"/*\" or \"/index.html\").
affects: >=0.0.0
Errors
Common errors & fixes
Error: The CloudFormation template is invalid: ... Output ... not found
The `distributionIdKey` references a CloudFormation output that does not exist in the same serverless.yml stack.
fix
Define the CloudFormation Output in the resources section with the same key, or use a literal `distributionId` instead.
Error: Cannot find module 'serverless-cloudfront-invalidate'
The npm package is not installed, or the plugin name in serverless.yml is misspelled.
fix
Run `npm install --save-dev serverless-cloudfront-invalidate` and ensure the plugin name is exactly `serverless-cloudfront-invalidate`.
Error: Invalidation batch is too large for path /index.html
The `items` list contains an invalid path (e.g., missing leading slash) or exceeds CloudFront limits.
fix
Ensure all paths start with `/` and are URL-encoded if containing special characters. For large batches, use wildcards like `/static/*` or `/images/*` to reduce path count.
Upgrade
Version history
1.12.2latest on npm
Audit
Dependencies
serverlessrequiredPeer dependency; plugin requires the Serverless Framework to function.
Agent activity
7 hits · last 30 days
node
6
Resources
serverless-cloudfront-invalidate — npm install serverless-cloudfront-invalidate · libregistry