We have a CDK project with several stacks, one of them is going to deploy OpenSearch and it needs "AWSServiceRoleForAmazonOpenSearchService" to exists before the actual resource being deployed. We deploy this project to many fresh accounts and as a multi region deployment (active active in us-east-1 and ap-northeast-2). Below is our code
if region == "us-east-1":
slr = iam.CfnServiceLinkedRole(
self,
f"{props.customer}-{region}-Service Linked Role",
aws_service_name="es.amazonaws.com",
)
domain = opensearchservice.Domain(...)
迄今为止,这一守则是行之有效的,但今后我们可能在非我们东部-1或东北部2的地区部署,这将打破我们的守则,或者如果 st部署首先是东北部2,这也将打破逻辑,因为这一作用将只部署我们东部-1,而分遣队将在东北部2部署非洲顾问领域。
最好的逻辑不是根据区域进行核查,而是根据存在的作用进行核查。
if slr.alreadyExists
continue
else
create slr role
然而,一看AWS CDK 或其它职位中提到的情况,是可能的,还是还有另一种将发挥作用的替代方法?