How to invalidate a Cloudfront Distribution using the Python CDK?

0

This is for a static site served from an s3 bucket.

I have this:

distribution = aws_cloudfront.Distribution.from_distribution_attributes(self,
                                                                                id="ImportedDistribution",
                                                                                domain_name='https://hgfdh.cloudfront.net',
                                                                                distribution_id='hgfdhgfdh')

        #now invalidate the distribution
        distribution.invalidate(
            aws_cloudfront.InvalidationBatch(
                paths=['/*'],
                caller_reference=f'Invalidate {distribution.distribution_id}'
            )
        )

but I get: AttributeError: '<class 'aws_cdk.Resource'>+<class 'aws_cdk.aws_cloudfront._IDistributionProxy'>' object has no attribute 'invalidate'

1개 답변
1

I think this is correct, you do it as part of the BucketDepolyment:

aws_s3_deployment.BucketDeployment(self, "DeployWithInvalidation",
                                           sources=[aws_s3_deployment.Source.asset("./build/fdsf')],
                                           destination_bucket=website_bucket,
                                           distribution=distribution,
                                           distribution_paths=['/*'],
                                           )

https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_s3_deployment/README.html#cloudfront-invalidation

Mick B
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠