Skip to content

Commit 0d4417e

Browse files
committed
Fix missing NotificationConfiguration for S3WebsiteDistribution
`S3WebsiteDistribution.add_cache_invalidation` is called after `Bucket.resources` and so the `NotificationConfiguration` of the bucket are missing from the stack template
1 parent 7f5bcae commit 0d4417e

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

src/e3/aws/troposphere/cloudfront/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,17 @@ def resources(self, stack: Stack) -> list[AWSObject]:
306306
# Add bucket policy granting read access to te cloudfront distribution
307307
self.add_oai_access_to_bucket()
308308

309+
# Add a lambda invalidating cloudfront cache when bucket objects are modified
310+
invalidation_resources = self.add_cache_invalidation(stack)
311+
309312
result = [
310313
*(self.bucket.resources(stack) if self._create_bucket else []),
311314
self.cache_policy,
312315
self.distribution,
313316
self.origin_access_identity,
314317
]
315318

316-
# Add a lambda invalidating cloudfront cache when bucket objects are modified
317-
result.extend(self.add_cache_invalidation(stack))
319+
result.extend(invalidation_resources)
318320

319321
# Add route53 records if needed
320322
if self.r53_route_from:

tests/tests_e3_aws/troposphere/s3websitedistribution.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"HostBucket": {
33
"DeletionPolicy": "Retain",
4+
"DependsOn": [
5+
"TestS3wDistInvalidationTopicPolicy"
6+
],
47
"Properties": {
58
"BucketName": "host-bucket",
9+
"NotificationConfiguration": {
10+
"TopicConfigurations": [
11+
{
12+
"Event": "s3:ObjectCreated:*",
13+
"Topic": {
14+
"Ref": "TestS3wDistInvalidationTopic"
15+
}
16+
}
17+
]
18+
},
619
"BucketEncryption": {
720
"ServerSideEncryptionConfiguration": [
821
{

tests/tests_e3_aws/troposphere/s3websitedistribution_iam_path.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"HostBucket": {
33
"DeletionPolicy": "Retain",
4+
"DependsOn": [
5+
"TestS3wDistInvalidationTopicPolicy"
6+
],
47
"Properties": {
58
"BucketName": "host-bucket",
9+
"NotificationConfiguration": {
10+
"TopicConfigurations": [
11+
{
12+
"Event": "s3:ObjectCreated:*",
13+
"Topic": {
14+
"Ref": "TestS3wDistInvalidationTopic"
15+
}
16+
}
17+
]
18+
},
619
"BucketEncryption": {
720
"ServerSideEncryptionConfiguration": [
821
{

tests/tests_e3_aws/troposphere/s3websitedistribution_logging.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"HostBucket": {
33
"DeletionPolicy": "Retain",
4+
"DependsOn": [
5+
"TestS3wDistInvalidationTopicPolicy"
6+
],
47
"Properties": {
58
"BucketName": "host-bucket",
9+
"NotificationConfiguration": {
10+
"TopicConfigurations": [
11+
{
12+
"Event": "s3:ObjectCreated:*",
13+
"Topic": {
14+
"Ref": "TestS3wDistInvalidationTopic"
15+
}
16+
}
17+
]
18+
},
619
"BucketEncryption": {
720
"ServerSideEncryptionConfiguration": [
821
{

tests/tests_e3_aws/troposphere/s3websitedistribution_logging_default.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"HostBucket": {
33
"DeletionPolicy": "Retain",
4+
"DependsOn": [
5+
"TestS3wDistInvalidationTopicPolicy"
6+
],
47
"Properties": {
58
"BucketName": "host-bucket",
9+
"NotificationConfiguration": {
10+
"TopicConfigurations": [
11+
{
12+
"Event": "s3:ObjectCreated:*",
13+
"Topic": {
14+
"Ref": "TestS3wDistInvalidationTopic"
15+
}
16+
}
17+
]
18+
},
619
"BucketEncryption": {
720
"ServerSideEncryptionConfiguration": [
821
{

tests/tests_e3_aws/troposphere/s3websitedistribution_py313.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
{
22
"HostBucket": {
33
"DeletionPolicy": "Retain",
4+
"DependsOn": [
5+
"TestS3wDistInvalidationTopicPolicy"
6+
],
47
"Properties": {
58
"BucketName": "host-bucket",
9+
"NotificationConfiguration": {
10+
"TopicConfigurations": [
11+
{
12+
"Event": "s3:ObjectCreated:*",
13+
"Topic": {
14+
"Ref": "TestS3wDistInvalidationTopic"
15+
}
16+
}
17+
]
18+
},
619
"BucketEncryption": {
720
"ServerSideEncryptionConfiguration": [
821
{

0 commit comments

Comments
 (0)