# cdnInvalidate

This step invalidates the CloudFront cache for a given application.

## Parameters

| Name             | Description                                      | Type           | Default     | Required |
| ---------------- | ------------------------------------------------ | -------------- | ----------- | -------- |
| appName          | The application name to clear caches for         | `String`       | n/a         | yes      |
| env              | The environment ["qa", "prod"]                   | `String`       | n/a         | yes      |
| awsRegion        | The aws region name                              | `String`       | 'us-east-1' | no       |
| distributions    | Array of CloudFront distribution ids             | `List<String>` | null        | no       |
| waitOnCompletion | If true, will wait until the operation completes | `Boolean`      | false       | no       |

### Usage

This step requires two parameters, `appName` and `env`.
The `appName` parameter defines the application that we should clear the CDN cache for. It is usually the same as the Github repo name. e.g "frontend-settings".
The `env` parameter specifies which CloudFront distributions we should clear.

### Changing the AWS region

Use the `awsRegion` parameter to specify a different region than the default: "us-east-1".

```groovy
cdnInvalidate(
    env: 'qa',
    appName: 'frontend-settings',
    awsRegion: 'us-west-1'
)
```

### Providing distribution ids to clear

By default, we automatically determine the distributions based on the `appName` and `env` parameters.
Override it by using the `distributions` parameter.

```groovy
cdnInvalidate(
    env: 'qa',
    appName: 'frontend-settings',
    distributions: ['1234', '5678']
)
```

### Wait on completion

By default we do not wait for CloudFront to confirm the caches are cleared.
Use the `waitOnCompletion` parameter to wait until the remote operation is done.

```groovy
cdnInvalidate(
    env: 'qa',
    appName: 'frontend-settings',
    waitOnCompletion: true
)
```

## References
- [Cache invalidation script](https://github.com/theorchard/python-deployment-utils/blob/a8bbc7658218cc2fad8d1ff4ad05d526b3bf66cc/cloudfront/invalidate_caches.py#L4)
- [Jenkins cfInvalidate step](https://github.com/jenkinsci/pipeline-aws-plugin?tab=readme-ov-file#cfinvalidate)
