# ea-serverless-cloudfront-invalidate

> Serverless plugin that allows you to invalidate Cloudfront Cache

Latest version **1.11.0** (published 2022-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install ea-serverless-cloudfront-invalidate
pnpm add ea-serverless-cloudfront-invalidate
yarn add ea-serverless-cloudfront-invalidate
bun add ea-serverless-cloudfront-invalidate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.11.0 |
| Published | 2022-05-30 |
| First published | 2022-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Amir Ghadiry |
| Maintainers | tal-ea |

## Links

- npm: https://www.npmjs.com/package/ea-serverless-cloudfront-invalidate
- Repository: https://github.com/aghadiry/serverless-cloudfront-invalidate
- Homepage: https://github.com/aghadiry/serverless-cloudfront-invalidate#readme
- Issues: https://github.com/aghadiry/serverless-cloudfront-invalidate/issues
- npm.io page: https://npm.io/package/ea-serverless-cloudfront-invalidate

## Dependencies (4)

- [chalk](https://npm.io/package/chalk.md) ^2.3.1
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.224.1
- [proxy-agent](https://npm.io/package/proxy-agent.md) ^5.0.0
- [randomstring](https://npm.io/package/randomstring.md) ^1.1.5

## Recent versions

- 1.11.0 (latest) — 2022-05-30

## README

# serverless-cloudfront-invalidate

Serverless plugin that allows you to invalidate Cloudfront Cache

## Install

Run `npm install` in your Serverless project.

```sh
$ npm install --save serverless-cloudfront-invalidate
```

## Setup

Add the plugin to your serverless.yml file as the last plugin

```yaml
plugins:
  - serverless-cloudfront-invalidate # add as the last plugin
```

If the CDN is created as part of same serverless.yml then you can specify the `distributionIdKey` and output the DomainId (as shown in the sample below).

```yaml
custom:
  cloudfrontInvalidate:
    - distributionId: "CLOUDFRONT_DIST_ID" #conditional, distributionId or distributionIdKey is required.
      distributionIdKey: "CDNDistributionId" #conditional, distributionId or distributionIdKey is required.
      autoInvalidate: true # Can be set to false to avoid automatic invalidation after the deployment. Useful if you want to manually trigger the invalidation later. Defaults to true.
      items: # one or more paths required
        - "/index.html"
      stage: "dev"  # conditional, the stage that this cloudfront invalidation should be created
            # this should match the provider's stage you declared, e.g. "dev" but not "prod" in this case
            # an invalidation for this distribution will be created when executing `sls deploy --stage dev`
    - distributionId: "CLOUDFRONT_DIST_ID" #conditional, distributionId or distributionIdKey is required.
      distributionIdKey: "CDNDistributionId" #conditional, distributionId or distributionIdKey is required.
      items: # one or more paths required
        - "/index.html"
      # `stage` is omitted, an invalidation will be created for this distribution at all stages
resources:
  Resources:
    CDN:
      Type: "AWS::CloudFront::Distribution"
      Properties: ....
  Outputs:
    CDNDistributionId:
      Description: CDN distribution id.
      Value:
        Ref: CDN
```

## Usage

Run `sls deploy`. After the deployment a Cloudfront Invalidation will be started.
Run `sls cloudfrontInvalidate` to do a standalone invalidation

### Options

The following options are supported:

##### cacert

Used to specify a cacert file for the AWS commands. This is useful for self signed certificates. You will need to specify the self signed cert in 2 places, one for the serverless execution and one for the AWS execution.

- Use `export cafile=<path to cert file>` to use self signed cert for serverless execution
- Run `sls cloudfrontInvalidate --cacert=<path to ca cert file>` to use self signed cert for AWS execution

##### Proxy

You can communicate with AWS even if you are using a proxy by setting the proxy to the environment variable of the execution environment.

- Correspond to the following environment variable names

  - proxy
  - HTTP_PROXY
  - http_proxy
  - HTTPS_PROXY
  - https_proxy

- example

  windows: `set HTTP_PROXY=http://localhost:8080`

  mac: `export HTTP_PROXY=http://localhost:8080`

---
_Source: https://npm.io/package/ea-serverless-cloudfront-invalidate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
