You can use an existing InstanceProfile instead of creating a new one from within the stack. In fact, one might already be created for you - from the docs:
If you use the AWS Management Console to create a role for Amazon EC2, the console automatically creates an instance profile and gives it the same name as the role.
This means that you might not have to create an AWS::IAM::InstanceProfile
resource in the stack. However note that also:
The console does not create an instance profile for a role that is not associated with Amazon EC2.
In this case you can do it manually from AWS CLI using these 2 commands:
aws iam create-instance-profile --instance-profile-name MyExistingRole
aws iam add-role-to-instance-profile --instance-profile-name MyExistingRole --role-name MyExistingRole
Then, provided you've defined a role in the UI named MyExistingRole
, this will be sufficient:
"Resources" : {
"Instance" : {
"Type" : "AWS::EC2::Instance",
...
"Properties" : {
"IamInstanceProfile" : "MyExistingRole",
...
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…