将现有 IAM 角色与 CloudFormation 中的 EC2 实例相关联 [英] Associate existing IAM role with EC2 instance in CloudFormation
问题描述
如何为 EC2 实例使用现有的 IAM 角色,而不是在我的 CloudFormation 模板中创建一个新角色?
How can I use an existing IAM role for an EC2 instance, as opposed to creating a new one in my CloudFormation template?
例如,我在 AWS 控制台中创建了一个角色并且只想使用它.
For example, I have created a role in AWS Console and just want to use that.
推荐答案
您需要一个实例配置文件、一个角色和实例信息(或启动配置)本身.
You need an instance profile, a role, and the instance info (or launch configuration) itself.
您的实例配置文件如下所示:
Your instance profile would look like this:
"Resources" : {
"InstanceProfile" : {
"Type" : "AWS::IAM::InstanceProfile",
"Properties" : {
"Path" : "/",
"Roles" : ["MyExistingRole"]
}
},
"Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"IamInstanceProfile" : {"Ref" : "InstanceProfile"}
...
}
}
特别是 - 请注意,实例配置文件中的引用是对现有角色名称的引用
另外 - 我写过关于引导实例的文章,它使用实例配置文件和角色,以确保我们不会持续安全.
Also - I've written about bootstrapping instances which uses instance profiles and roles to ensure we're not persisting security.
关键是使用角色的实际名称而不是使用 {"Ref" : RoleName} 等.
The key thing is rather than using the {"Ref" : RoleName} etc, to use the actual name of the role.
这篇关于将现有 IAM 角色与 CloudFormation 中的 EC2 实例相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!