Create AWS IAM Credentials for CloudFront Cache Invalidation¶
Summary¶
Use this guide when SkyCMS needs AWS credentials to trigger CloudFront cache invalidations after content is published.
Outcome¶
After completing this guide, you will have a least-privilege IAM user with an access key scoped to CloudFront cache invalidation on the target distribution, ready to store as SkyCMS CDN credentials.
What SkyCMS needs¶
SkyCMS needs these values for CloudFront CDN purge:
Access Key IDSecret Access KeyDistribution IDRegion— useus-east-1for CloudFront API calls regardless of where your origin is located
Before you start¶
- Confirm your CloudFront distribution already exists and is serving your site.
- Have an AWS account with permission to create IAM users and policies.
- CloudFront's API endpoint is global but the region you supply to the AWS SDK should be
us-east-1.
Step 1: Find the Distribution ID¶
- Sign in to the AWS Management Console.
- Open CloudFront from the Services menu (or search
CloudFrontin the search bar). - In the Distributions list, locate the distribution for your site.
- Copy the Distribution ID (for example,
E1ABCDEF2GHIJK). This is not the domain name.
Step 2: Create a least-privilege IAM policy¶
- Open IAM from the Services menu.
- In the left navigation, select Policies.
- Select Create policy.
- On the Specify permissions step, select the JSON tab.
- Replace the default content with the following, substituting your distribution ID:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SkyCMSCloudFrontInvalidation",
"Effect": "Allow",
"Action": [
"cloudfront:CreateInvalidation",
"cloudfront:GetInvalidation",
"cloudfront:ListInvalidations"
],
"Resource": "arn:aws:cloudfront::ACCOUNT-ID:distribution/YOUR-DISTRIBUTION-ID"
}
]
}
Replace ACCOUNT-ID with your 12-digit AWS account ID and YOUR-DISTRIBUTION-ID with the ID from Step 1.
- Select Next.
- Enter a descriptive name such as
SkyCMS-CloudFront-Invalidation-Production. - Select Create policy.
To find your account ID: open the account menu in the top-right corner of the AWS console. The ID appears under your account name.
Step 3: Create an IAM user¶
- In the IAM left navigation, select Users.
- Select Create user.
- Enter a User name such as
skycms-cdn-production. - Leave Provide user access to the AWS Management Console unchecked.
- Select Next.
- On the Set permissions step, select Attach policies directly.
- Search for
SkyCMS-CloudFront-Invalidation-Productionand check the box next to it. - Select Next, then Create user.
Step 4: Create an access key¶
- On the Users list, select the user you just created.
- Open the Security credentials tab.
- Scroll to Access keys and select Create access key.
- Select Application running outside AWS.
- Optionally add a description tag such as
SkyCMS CloudFront invalidation key. - Select Next, then Create access key.
- Copy the Access key (Access Key ID) and Secret access key.
AWS only shows the secret access key once. Store both values immediately in your secret manager.
Step 5: Map values into SkyCMS¶
Enter the following values in the SkyCMS CDN settings or set them as environment variables:
| SkyCMS setting | Value |
|---|---|
CloudFrontAccessKeyId |
Access Key ID from Step 4 |
CloudFrontSecretAccessKey |
Secret Access Key from Step 4 |
CloudFrontDistributionId |
Distribution ID from Step 1 |
CloudFrontRegion |
us-east-1 |
See CDN: CloudFront for the full configuration reference.
Common mistakes¶
- Using the CloudFront domain name (for example,
dXXXXXXX.cloudfront.net) instead of the distribution ID in the policy resource. The policy requires the distribution ID. - Setting region to the origin region instead of
us-east-1. CloudFront's API is always inus-east-1. - Omitting
cloudfront:GetInvalidation— this can cause SkyCMS to fail validation checks even if the invalidation itself succeeds. - Granting
cloudfront:*on*— this gives access to every distribution in the account.
Validation¶
To verify the credentials work, you can test with the AWS CLI:
aws cloudfront create-invalidation \
--distribution-id YOUR-DISTRIBUTION-ID \
--paths "/*" \
--region us-east-1
A successful response includes an Invalidation object with Status: InProgress.
Key rotation¶
Rotate access keys periodically:
- Create a new access key for the same user.
- Update SkyCMS with the new values and verify invalidations work.
- Deactivate and delete the old key.