代码之家  ›  专栏  ›  技术社区  ›  Woody1193 Nimmi Rashinika

由于无效的arn,AWS附加策略角色返回400

  •  0
  • Woody1193 Nimmi Rashinika  · 技术社区  · 6 年前

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "",
                "Effect": "Allow",
                "Principal": {
                    "Service": [
                        "codedeploy.amazonaws.com"
                    ]
                },
                "Action": "sts:AssumeRole"
            }
        ]
    }
    

    并将文件另存为 service-role.json

    aws iam create-role --role-name MyServiceRole --assume-role-policy-document file://service-role.json
    

    我得跑了。。。最终。返回了一些JSON:

    {                                                                               
        "Role": {                                                                   
            "Path": "/",                                                            
            "RoleName": "MyServiceRole",                                
            "RoleId": "SOMESTRINGOFRANDOMALPHANUMERICS",                                      
            "Arn": "arn:aws:iam::1123445569:role/MyServiceRole",      
            "CreateDate": "2018-08-31T03:18:24Z",                                   
            "AssumeRolePolicyDocument": {                                           
                "Version": "2012-10-17",                                            
                "Statement": [                                                      
                    {                                                               
                        "Sid": "",                                                  
                        "Effect": "Allow",                                          
                        "Principal": {                                              
                            "Service": [                                            
                                "codedeploy.amazonaws.com"                          
                            ]                                                       
                        },                                                          
                        "Action": "sts:AssumeRole"                                  
                    }                                                               
                ]
            }
        }
    }
    

    所有这些看起来都是正确的,所以我试着跑:

    aws iam attach-role-policy --role-name MyServiceRole --policy-arn arn:aws:iam::1123445569:role/MyServiceRole
    

    还有。。。我得到了回应

    An error occurred (InvalidInput) when calling the AttachRolePolicy operation: ARN arn:aws:iam::1123445569:role/MyServiceRole is not valid.
    

    我已经在互联网上寻找解决办法,因为看起来我做了什么 this

    1 回复  |  直到 6 年前
        1
  •  1
  •   Lech Migdal    6 年前

    而不是附加您已创建(并且已附加到)的假定角色策略 mentioned tutorial (步骤3),因此:

    aws iam attach-role-policy --role-name MyServiceRole --policy-arn arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole
    

    aws iam attach-role-policy --role-name MyServiceRole --policy-arn arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda