【问题标题】:Cloud formation error in creating the Role with managed policy and inline policy使用托管策略和内联策略创建角色时出现云形成错误
【发布时间】:2019-09-14 18:39:27
【问题描述】:

当我运行此堆栈时,我收到以下错误。第一次在AWS文档的帮助下尝试,但仍然无法找出错误。

通过这个 CFT,我正在尝试使用托管策略创建一个角色并将一个内联策略附加到它

Syntax errors in policy. (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument

但无法弄清楚缺少语法的地方,有人可以在这里帮助我吗?

    "EMRDefaultRole": {
        "Type": "AWS::IAM::Role",
        "Properties": {
            "RoleName": "EMR_DefaultRole",
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [ {
                    "Effect": "Allow",
                    "Principal": {
                        "Service": "elasticmapreduce.amazonaws.com"
                    },
                    "Action": "sts:AssumeRole"
                } ]
            },
            "ManagedPolicyArns": [
                "arn:aws:iam::aws:policy/service-role/AmazonElasticMapReduceRole"
            ]
        }
    },
    "EMRS3Policies": {
        "Type": "AWS::IAM::Policy",
        "Properties": {
            "PolicyName": "Moodys-IAM-EMR-S3-Access-Policy",
            "PolicyDocument": {
                    "Statement": [{
                        "Effect": "Allow",
                        "Action": [
                            "s3:HeadBucket",
                            "s3:ListObjects"
                        ],
                        "Resource": {["Fn::Join",[
                                "-",
                                [
                                    "mit",
                                    {
                                        "Ref": "AWS::AccountId"
                                    }
                                    "emr-files/*"
                                ]]
                                ]}
                    }]
            },
        "Roles": [{"Ref": "EMRDefaultRole"}]

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    Resource 键有问题,您错误地使用了Fn::Join。应该是:

    {
      "Resource": {
        "Fn::Join": [
          "",
          [
            "arn:aws:s3:::mit-",
            { "Ref": "AWS::AccountId" },
            "-emr-files/*"
          ]
        ]
      }
    }
    

    【讨论】:

    • 我试过了,但它没有在 arn:aws:s3:::mit-accountnuber-emr-files 中创建。它只是在创建 mit-emr-files.."Resource": { "Fn::Join": [ "-", [ "mit", { "Ref": "AWS::AccountId" }, "emr-files /*" ]] } } ] },
    • 更新了我的答案,它现在应该给你arn:aws:s3:::mit-<ACCOUNT>-emr-files/*。您的问题不清楚。
    猜你喜欢
    • 2018-11-20
    • 1970-01-01
    • 2017-01-31
    • 2020-09-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 2022-01-20
    • 2017-11-02
    相关资源
    最近更新 更多