All Projects β†’ chetan β†’ invalidate-cloudfront-action

chetan / invalidate-cloudfront-action

Licence: MIT License
Invalidate AWS CloudFront distribution paths

Programming Languages

shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to invalidate-cloudfront-action

perseverance
Make your functions πŸ’ͺ resilient and πŸš₯ fail-fast to πŸ’© failures or ⌚ delays
Stars: ✭ 12 (-85.71%)
Mutual labels:  github-actions
Github-Actions-React-Native
Github Action for React Native Build 🦊
Stars: ✭ 99 (+17.86%)
Mutual labels:  github-actions
latex-action
GitHub Action to compile LaTeX documents
Stars: ✭ 123 (+46.43%)
Mutual labels:  github-actions
cuda-toolkit
GitHub Action to install CUDA
Stars: ✭ 34 (-59.52%)
Mutual labels:  github-actions
ghaction-upx
GitHub Action for UPX, the Ultimate Packer for eXecutables
Stars: ✭ 27 (-67.86%)
Mutual labels:  github-actions
redis-github-action
Use Redis in GitHub Actions
Stars: ✭ 56 (-33.33%)
Mutual labels:  github-actions
action-autotag
Automatically generate a new tag when the manifest file (package.json, Dockerfile, custom file, etc) version changes.
Stars: ✭ 45 (-46.43%)
Mutual labels:  github-actions
cfn-lint-action
GitHub Action for interacting with CloudFormation Linter
Stars: ✭ 41 (-51.19%)
Mutual labels:  github-actions
release-notify-action
GitHub Action that triggers e-mails with release notes when these are created
Stars: ✭ 64 (-23.81%)
Mutual labels:  github-actions
jcefbuild
Binary builds of java-cef
Stars: ✭ 160 (+90.48%)
Mutual labels:  github-actions
Setup-Nuget
Set up your GitHub Actions workflow with the latest version of Nuget.exe CLI tool
Stars: ✭ 27 (-67.86%)
Mutual labels:  github-actions
autoupdate
A GitHub Action that auto-updates pull requests branches, whenever changes are pushed to their destination branch.
Stars: ✭ 70 (-16.67%)
Mutual labels:  github-actions
sentry
GitHub Actions for interacting with Sentry.io
Stars: ✭ 14 (-83.33%)
Mutual labels:  github-actions
autoSubmit
εŒ—δΊ¬ε€§ε­¦η–«ζƒ…ε‡Ίε…₯ζ ‘θ‡ͺ动呫ζŠ₯
Stars: ✭ 47 (-44.05%)
Mutual labels:  github-actions
markdown-to-pdf
A GitHub Action to make PDF and HTML files from Markdown
Stars: ✭ 33 (-60.71%)
Mutual labels:  github-actions
megalinter
πŸ¦™ Mega-Linter analyzes 48 languages, 22 formats, 19 tooling formats, excessive copy-pastes, spelling mistakes and security issues in your repository sources with a GitHub Action, other CI tools or locally.
Stars: ✭ 534 (+535.71%)
Mutual labels:  github-actions
commit-comment
A GitHub action to create a comment for a commit on GitHub
Stars: ✭ 62 (-26.19%)
Mutual labels:  github-actions
CIAnalyzer
A tool collecting multi CI services build data and export it for creating self-hosting build dashboard.
Stars: ✭ 52 (-38.1%)
Mutual labels:  github-actions
actions-setup-perl
Setup Perl environment Action
Stars: ✭ 51 (-39.29%)
Mutual labels:  github-actions
qodana-action
βš™οΈ Scan your Java, Kotlin, PHP, Python, JavaScript, TypeScript projects at GitHub with Qodana
Stars: ✭ 112 (+33.33%)
Mutual labels:  github-actions

Invalidate AWS CloudFront action

A GitHub Workflow Action for invalidating CloudFront distribution paths

Usage

- name: Invalidate CloudFront
  uses: chetan/invalidate-cloudfront-action@v2
  env:
    DISTRIBUTION: ${{ secrets.DISTRIBUTION }}
    PATHS: "/index.html"
    AWS_REGION: "us-east-1"
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

See also a sample workflow which illustrates a static site build and deploy.

Configuration

Param Required? Description
PATHS yes* A list of one or more space-separated paths to invalidate
PATHS_FROM yes* Filename to read list of paths from
DISTRIBUTION yes CloudFront distribution ID to operate on, e.g., 'EDFDVBD6EXAMPLE'
AWS_REGION yes AWS Region to operate in
AWS_ACCESS_KEY_ID yes Access key with necessary permissions to invalidate objects in the target distribution (see below)
AWS_SECRET_ACCESS_KEY yes Secret key
DEBUG no When set to "1", prints the final awscli invalidation command for troubleshooting purposes

Note: either PATHS or PATHS_FROM is required. PATHS_FROM will overwrite PATHS if both are set.

See also: AWS CLI reference

Paths

Paths are passed directly to the aws cli create-invalidation command and so must be a proper space-separated list of paths. Examples:

PATHS=/index.html
PATHS=/ /index.html /foo/bar/baz

Alternatively, you can write the list of files to invalidate to a file which will then be slurped into the PATHS variable. This lets you use some other method to dynamically generate the list of files based on the commit, etc. Example workflow steps:

- name: checkout dist
  uses: actions/checkout@master
  with:
    ref: dist
    # need at least 2 here so we can get a proper log in next step
    fetch-depth: 2

- name: get updated files
  run: |
    # allow grep to fail
    set +e
    FILES=$(git log --stat="1000" -1 | grep '|' | awk '{print "/"$1}' | grep -e '\.html$')
    set -e
    [ -z "$FILES" ] && touch .updated_files && exit 0
    for file in $FILES; do
      echo $file
      # add bare directory to list of updated paths when we see index.html
      [[ "$file" == *"/index.html" ]] && echo $file | sed -e 's/\/index.html$/\//'
    done | sort | uniq | tr '\n' ' ' > .updated_files

- name: invalidate
  uses: chetan/invalidate-cloudfront-action@v2
  env:
    PATHS_FROM: .updated_files
    AWS_REGION: 'us-east-1'
    DISTRIBUTION: ${{ secrets.DISTRIBUTION }}
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

AWS Credentials

The recommended way to pass AWS credentials to your GitHub actions is to use OpenID Connect.

Once configured, you can use the aws-actions/configure-aws-credentials action to properly authentication and supply AWS credentials to subsequent steps in your workflow.

Note that your workflow will need the following permission when using OIDC:

permissions:
  id-token: write

For a complete example, see the workflow in this repository.

Also note that if you using the CloudFormation template from the aws repo above, the 'thumbprint' shown in the example is out of date. I've included a working template complete with the below IAM policy that should work out of the box (as of 2022-01-27).

As an alternative, you may directly pass an access/secret key pair. See the config section above.

AWS IAM Policy

In order to use this action, you will need to supply credentials which have, at minimum, the following permission:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "cloudfront:CreateInvalidation",
            "Resource": "arn:aws:cloudfront::<account id>:distribution/<distribution ID>"
        }
    ]
}

Self-hosted runners

A note regarding self-hosted runners:

V2 of the invalidate-cloudfront-action executes via a bash script on the runner and requires the following additional tools:

  • jq 1.6
  • aws 1.x+
  • tr
  • date

Please ensure that they are available on your system or use V1 of the action, which executes within a docker container.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].