In CloudFront, we can invalidate the cache on demand by using GitHub Actions. This is necessary to ensure that the latest code updates are reflected on our website. You can view the full code here.
Update Identity and Access Management (IAM)
In our IAM, we need to add a new statement for the CloudFront Distribution.
{
"Version": "2012-10-17",
"Statement": [
...
{
"Action": [
"cloudfront:CreateInvalidation"
],
"Effect": "Allow",
"Resource": [
"arn:aws:cloudfront::000581027806:distribution/E2KRF40UYXVA3O"
]
}
...
]
}
You can find the CloudFront Distribution here.
Update Github Action
Let’s add the CloudFront Distribution to the GitHub Secrets with the AWS_CF_DISTRIBUTION
variable name. Next, we will add new steps to perform CloudFront Invalidation in the GitHub Action.
Also, let’s make some changes in our code to verify if the text will be updated.
Next, let’s create a new branch and push it to the main
branch, then wait for the workflow to finish.
When you observe the CloudFront, you will notice that a new invalidation has been created. Check our website to confirm the changes.
Top comments (0)