Serverless: Create a CloudFront invalidation when S3 origin contents changed
Create an invalidation for a CloudFront distribution when S3 origin objects changed.
I need to filter origin objects by prefix and suffix.
- Receive event notifications when S3 origin objects changed (
ObjectCreated
,ObjectRemoved
) - Invoking AWS Lambda functions via Amazon S3 events
- Create an invalidation for a CloudFront distribution to remove a file from CloudFront edge caches
- S3 Bucket
- CloudFront Distribution
- Lambda (python3.8)
$ DISTRIBUTION_ID=CF_DISTRIBUTION_ID \
S3_ORIGIN_BUCKET=YOUR_BUCKET_NAME \
PREFIX=hls \
SUFFIX=m3u8 \
serverless deploy
S3_ORIGIN_BUCKET
S3 Bucket NameDISTRIBUTION_ID
CloudFront distribution id
PREFIX
Configure notifications to be filtered by the prefix of the key name of objectsSUFFIX
Configure notifications to be filtered by the suffix of the key name of objects