Skip to content

Commit a24afae

Browse files
committed
ensuring the policy template remains a template
1 parent 20e9a0e commit a24afae

File tree

1 file changed

+5
-4
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/src

1 file changed

+5
-4
lines changed

aws_sra_examples/solutions/genai/bedrock_org/lambda/src/sra_s3.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,17 @@ def apply_bucket_policy(self, bucket: str) -> None:
102102
Args:
103103
bucket (str): Name of the S3 bucket to apply the policy to
104104
"""
105-
self.LOGGER.info(self.BUCKET_POLICY_TEMPLATE)
106-
for sid in self.BUCKET_POLICY_TEMPLATE["Statement"]:
105+
self.LOGGER.info(f"Original policy template: {self.BUCKET_POLICY_TEMPLATE}")
106+
policy_template = json.loads(json.dumps(self.BUCKET_POLICY_TEMPLATE))
107+
for sid in policy_template["Statement"]:
107108
if isinstance(sid["Resource"], list):
108109
sid["Resource"] = list(map(lambda x: x.replace("BUCKET_NAME", bucket), sid["Resource"])) # noqa C417
109110
else:
110111
sid["Resource"] = sid["Resource"].replace("BUCKET_NAME", bucket)
111-
self.LOGGER.info(self.BUCKET_POLICY_TEMPLATE)
112+
self.LOGGER.info(f"Updated policy template: {policy_template}")
112113
bucket_policy_response = self.S3_CLIENT.put_bucket_policy(
113114
Bucket=bucket,
114-
Policy=json.dumps(self.BUCKET_POLICY_TEMPLATE),
115+
Policy=json.dumps(policy_template),
115116
)
116117
self.LOGGER.info(bucket_policy_response)
117118

0 commit comments

Comments
 (0)