Skip to content

Commit 5e141ab

Browse files
author
Taniya Mathur
committed
Fix NoSuchKey error when setting ACLs on main template files
- Check if main template files exist before attempting to set ACLs - Use head_object to verify file existence before put_object_acl - Skip silently if versioned main template doesn't exist (404 error) - Prevents 'The specified key does not exist' errors during ACL operations - Only attempt ACL operations on files that were actually uploaded
1 parent 73d3527 commit 5e141ab

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

publish.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,24 +1919,33 @@ def set_public_acls(self):
19191919
f"[yellow]Warning: Could not set ACL for {obj['Key']}: {e}[/yellow]"
19201920
)
19211921

1922-
# Also set ACL for main template files
1922+
# Also set ACL for main template files (only if they exist)
19231923
main_template_keys = [
19241924
f"{self.prefix}/{self.main_template}",
19251925
f"{self.prefix}/{self.main_template.replace('.yaml', f'_{self.version}.yaml')}",
19261926
]
19271927

19281928
for key in main_template_keys:
19291929
try:
1930+
# Check if the key exists first
1931+
self.s3_client.head_object(Bucket=self.bucket, Key=key)
1932+
# If it exists, set the ACL
19301933
self.s3_client.put_object_acl(
19311934
Bucket=self.bucket, Key=key, ACL="public-read"
19321935
)
19331936
successful_acls += 1
19341937
except ClientError as e:
1935-
failed_acls += 1
1936-
if "AccessDenied" not in str(e) and "BlockPublicAcls" not in str(e):
1937-
self.console.print(
1938-
f"[yellow]Warning: Could not set ACL for {key}: {e}[/yellow]"
1939-
)
1938+
if e.response["Error"]["Code"] == "404":
1939+
# Key doesn't exist, skip silently
1940+
continue
1941+
else:
1942+
failed_acls += 1
1943+
if "AccessDenied" not in str(
1944+
e
1945+
) and "BlockPublicAcls" not in str(e):
1946+
self.console.print(
1947+
f"[yellow]Warning: Could not set ACL for {key}: {e}[/yellow]"
1948+
)
19401949

19411950
# Report accurate final status
19421951
if failed_acls == 0:

0 commit comments

Comments
 (0)