AWS cloudfront缓存无效并不会直接清除原始屏蔽缓存。如果需要清除原始屏蔽缓存,需要使用AWS API来进行操作。具体步骤如下:
aws cloudfront list-distributions
aws cloudfront create-invalidation --distribution-id [distribution-id] --paths [file-path]
需要注意的是,[file-path]需要替换成需要清除原始屏蔽缓存的文件路径,如“/img/example.jpg”。
示例代码:
import boto3
def invalidate_cloudfront_cache(distribution_id, paths):
client = boto3.client('cloudfront')
response = client.create_invalidation(
DistributionId=distribution_id,
InvalidationBatch={
'Paths': {
'Quantity': len(paths),
'Items': paths
},
'CallerReference': 'string'
}
)
return response
distribution_id = '1234567890'
paths = ['/img/example.jpg']
response = invalidate_cloudfront_cache(distribution_id, paths)
print(response)