Skip to content

A Lambda function to invalidate CloudFront cache when files in S3 are changed

License

Notifications You must be signed in to change notification settings

adamking/s3-cloudfront-cache-invalidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

s3-cloudfront-cache-invalidation

An AWS Lambda function that invalidates AWS CloudFront cache when S3 objects are changed.

Installing and building

Install dependencies with yarn install. Build with yarn build.

AWS Setup

Create an AWS Lambda Function

Create Screenshot

Upload s3-cloudfront-cache-invalidation.zip to AWS Lambda

Upload Screenshot

Create policy

Policy Screenshot

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "acm:ListCertificates",
                "cloudfront:GetDistribution",
                "cloudfront:GetDistributionConfig",
                "cloudfront:ListDistributions",
                "cloudfront:ListCloudFrontOriginAccessIdentities",
                "cloudfront:CreateInvalidation",
                "cloudfront:GetInvalidation",
                "cloudfront:ListInvalidations",
                "elasticloadbalancing:DescribeLoadBalancers",
                "iam:ListServerCertificates",
                "sns:ListSubscriptionsByTopic",
                "sns:ListTopics",
                "waf:GetWebACL",
                "waf:ListWebACLs"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:Get*",
                "s3:List*"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "*"
        }
    ]
}

Add trigger to S3 bucket

About

A Lambda function to invalidate CloudFront cache when files in S3 are changed

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published