【发布时间】:2021-09-28 08:35:15
【问题描述】:
我是 cdk 新手,并尝试使用以下代码使用 CDK+Python 创建实例配置文件。我已经通过 CDK 成功创建了角色(gitLabRunner-glue),并希望将它与实例配置文件一起使用。但是,当我运行以下代码时,出现错误gitLabRunner-glue already exists
有人可以解释一下我错过了什么吗?
from aws_cdk import core as cdk
from aws_cdk import aws_glue as glue
from aws_cdk import aws_ec2 as _ec2
from aws_cdk import aws_iam as _iam
class Ec2InstanceProfile(cdk.Stack):
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# role = _iam.Role(self, "instanceprofilerole", role_name="gitLabRunner-glue",
# assumed_by=_iam.ServicePrincipal(service='ec2.amazonaws.com'))
ec2gitLabRunnerinstanceprofile = _iam.CfnInstanceProfile(
self,
"ec2gitLabRunnerinstanceprofile",
instance_profile_name="ec2-gitLabRunner-glue",
roles=["gitLabRunner-glue"] # also tried with this[role.role_name]
)
【问题讨论】:
标签: python amazon-ec2 amazon-cloudformation amazon-iam aws-cdk