https://github.com/baseline-js/serverless-baseline-invalidate-cloudfront
Serverless plugin that allows you to invalidate Cloudfront Cache
https://github.com/baseline-js/serverless-baseline-invalidate-cloudfront
Last synced: 4 months ago
JSON representation
Serverless plugin that allows you to invalidate Cloudfront Cache
- Host: GitHub
- URL: https://github.com/baseline-js/serverless-baseline-invalidate-cloudfront
- Owner: Baseline-JS
- License: mit
- Created: 2024-03-17T00:03:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-16T04:31:31.000Z (5 months ago)
- Last Synced: 2025-01-16T05:29:10.566Z (5 months ago)
- Language: TypeScript
- Size: 26.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# serverless-baseline-invalidate-cloudfront
Serverless plugin that allows you to invalidate Cloudfront Cache securely, addressing previous security concerns with the vm2 dependency. Based on the original package `serverless-cloudfront-invalidate`.
## Install
Install the updated plugin in your Serverless project.
```sh
$ npm install --save serverless-baseline-invalidate-cloudfront
```## Setup
Incorporate the plugin into your serverless.yml file as the final plugin.
```yaml
plugins:
- serverless-baseline-invalidate-cloudfront # Add this as the last plugin.
```For CloudFront distributions created within the same serverless.yml, you can specify the `distributionIdKey` and output the DomainId (as illustrated below).
```yaml
custom:
cloudfrontInvalidate:
- distributionId: "CLOUDFRONT_DIST_ID" # Either distributionId or distributionIdKey is required.
distributionIdKey: "CDNDistributionId" # Either distributionId or distributionIdKey is required.
autoInvalidate: true # Set to false to prevent automatic invalidation post-deployment. Defaults to true.
items: # Specify one or more paths
- "/index.html"
stage:
"staging" # Specify the deployment stage for this invalidation
# This should align with the provider's stage, e.g., "staging" instead of "prod"
# Invalidation for this distribution will be initiated with `sls deploy --stage staging`
- distributionId: "CLOUDFRONT_DIST_ID" # Either distributionId or distributionIdKey is required.
distributionIdKey: "CDNDistributionId" # Either distributionId or distributionIdKey is required.
items: # Specify one or more paths
- "/index.html"
# Omitting `stage` will trigger invalidation for this distribution across all stages
resources:
Resources:
CDN:
Type: "AWS::CloudFront::Distribution"
Properties: ....
Outputs:
CDNDistributionId:
Description: "CDN distribution id."
Value:
Ref: CDN
```## Usage
Execute `sls deploy`. Post-deployment, CloudFront Invalidation will commence.
To trigger a standalone invalidation, run `sls cloudfrontInvalidate`.