我们有一个托管在 S3 中的静态站点,我正在尝试创建一个堆栈,该堆栈将自动上传文件并使 Cloudfront 发行版失效。
我可以上传文件,但看不到任何创建失效的方法。
我可以得到这样的分布:
distribution = aws_cloudfront.Distribution.from_distribution_attributes(self,
id="ImportedDistribution",
domain_name='https://hgfdh.cloudfront.net',
distribution_id='hgfdh')
但看不到如何创建失效。
不幸的是,Python CDK 中没有用于失效的构造。这是 boto3 中的示例。
import boto3
def invalidate_cloudfront_distribution(distribution_id, paths):
client = boto3.client('cloudfront')
response = client.create_invalidation(
DistributionId=distribution_id,
InvalidationBatch={
'Paths': {
'Quantity': len(paths),
'Items': paths
},
'CallerReference': str(hash(tuple(paths)))
}
)
return response
您可以将其实现为 Lambda 函数吗?