使用 cloudformation 创建 AWS IAM 策略

create AWS IAM Policy using cloudformation

我有一个已经创建的 IAM 角色 (MyIAMrole)。我想使用 Cloudformation 模板将策略附加到此角色。

"Mypolicy":{
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyName": "assume-role-policy",
        "PolicyDocument": {
          "Version" : "2012-10-17",
        "Statement": [
        { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "*" }
      ]
    },
    "Roles": [ { "Ref": "arn:aws:iam::*:role/MyIAMrole" } ]
  }
}

当我尝试对此进行验证时,我收到一条错误消息 "Unreolved reference options"。

如何将此策略附加到已经存在的角色?

我通过引用角色的 名称 而不是 ARN,设法让您的代码片段正常工作。

根据 AWS::IAM::Policy documentation:

Roles: The names of AWS::IAM::Roles to which this policy will be attached.

但是,当堆栈转到 CREATE_COMPLETE 时,我看不到 IAM 的策略部分中列出的策略,也看不到附加到引用角色的策略。

可能您无法使用 CloudFormation 将策略附加到现有角色。您可能需要创建角色作为 CloudFormation 模板的一部分才能附加角色。