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 Antwort
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
beantwortet vor 5 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen