Skip to content

Commit 9e57911

Browse files
committed
attaching policies to oam cross account role; add oam link creation
1 parent 0699233 commit 9e57911

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ def create_event(event, context):
625625
DRY_RUN_DATA["OAMCrossAccountRoleCreate"] = f"DRY_RUN: Create {cloudwatch.CROSS_ACCOUNT_ROLE_NAME} IAM role"
626626
else:
627627
LOGGER.info(f"CloudWatch observability access manager cross-account role found: {cloudwatch.CROSS_ACCOUNT_ROLE_NAME}")
628+
629+
# 5d) Attach managed policies to CloudWatch-CrossAccountSharingRole IAM role
630+
cross_account_policies = [
631+
"arn:aws:iam::aws:policy/AWSXrayReadOnlyAccess",
632+
"arn:aws:iam::aws:policy/CloudWatchAutomaticDashboardsAccess",
633+
"arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"
634+
]
635+
636+
628637

629638

630639
# End

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,28 @@ def put_oam_sink_policy(self, sink_arn: str, sink_policy: dict) -> None:
317317
except ClientError as e:
318318
self.LOGGER.info(self.UNEXPECTED)
319319
raise ValueError(f"Unexpected error executing Lambda function. {e}") from None
320+
321+
def find_oam_link(self, sink_arn: str) -> tuple[bool, str]:
322+
"""Find the Observability Access Manager link for SRA in the organization.
323+
324+
Args:
325+
sink_arn (str): ARN of the sink
326+
327+
Returns:
328+
tuple[bool, str]: True if the link is found, False if not, and the link ARN
329+
"""
330+
try:
331+
response = self.CWOAM_CLIENT.list_links()
332+
for link in response["Items"]:
333+
if link["SinkArn"] == sink_arn:
334+
self.LOGGER.info(f"Observability access manager link for {sink_arn} found: {link['Arn']}")
335+
return True, link["Arn"]
336+
self.LOGGER.info(f"Observability access manager link for {sink_arn} not found")
337+
return False, ""
338+
except ClientError as error:
339+
if error.response["Error"]["Code"] == "ResourceNotFoundException":
340+
self.LOGGER.info(f"Observability access manager link for {sink_arn} not found. Error code: {error.response['Error']['Code']}")
341+
return False, ""
342+
else:
343+
self.LOGGER.info(self.UNEXPECTED)
344+
raise ValueError(f"Unexpected error executing Lambda function. {error}") from None

0 commit comments

Comments
 (0)