Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 使用cloudformation创建aws IAM角色不会创建角色策略_Amazon Web Services_Amazon Cloudformation_Amazon Iam - Fatal编程技术网

Amazon web services 使用cloudformation创建aws IAM角色不会创建角色策略

Amazon web services 使用cloudformation创建aws IAM角色不会创建角色策略,amazon-web-services,amazon-cloudformation,amazon-iam,Amazon Web Services,Amazon Cloudformation,Amazon Iam,我正在创建一个ec2实例,其角色提供对kinesis流和Dynamodb偏移表的访问。我正在用它 我遇到的问题是在创建自身时。 因此,我将有以下结构: has StreamingAccessRole ----------> RolePolicy1(kinesis:*), RolePolicy2(dynamodb:*) 创建AWS IAM角色的模板包含两个策略,一个用于kinesis,另一个用于dynamodb: { "AWSTempla

我正在创建一个ec2实例,其角色提供对kinesis流和Dynamodb偏移表的访问。我正在用它

我遇到的问题是在创建自身时。

因此,我将有以下结构:

                        has
StreamingAccessRole ----------> RolePolicy1(kinesis:*), RolePolicy2(dynamodb:*)
创建AWS IAM角色的模板包含两个策略,一个用于kinesis,另一个用于dynamodb:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "teamIdentifier": {
      "Type": "String",
      "Default": "a28",
      "Description": "Identifier for the team"
    }
  },
  "Resources": {
    "StreamingAccessRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "ec2.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "Path": "/a28/",
        "Policies": [
          {
            "PolicyName": "Stream-ConsumerOffset-RW-AccessPolicy",
            "PolicyDocument": {
              "Version": "2012-10-17",
              "Statement": [
                {
                  "Effect": "Allow",
                  "Action": "kinesis:*",
                  "Resource": "arn:aws:kinesis:us-west-2:*:stream/a28-*"
                },
                {
                  "Effect": "Allow",
                  "Action": "dynamodb:*",
                  "Resource": "arn:aws:dynamodb:us-west-2:*:table/a28-*"
                }
              ]
            }
          }
        ]
      }
    }
  }
}
它创建了访问角色,但没有角色策略

$ aws iam get-role --role-name a28-streaming-access-role-st-StreamingAccessRole-14QHMTIOIRN5X --region us-west-2 --profile aws-federated
{
    "Role": {
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17", 
            "Statement": [
                {
                    "Action": "sts:AssumeRole", 
                    "Effect": "Allow", 
                    "Principal": {
                        "Service": "ec2.amazonaws.com"
                    }
                }
            ]
        }, 
        "RoleId": "AROAIFD6X2CJXTKLVQNLE", 
        "CreateDate": "2017-04-07T18:54:59Z", 
        "RoleName": "a28-streaming-access-role-st-StreamingAccessRole-14QHMTIOIRN5X", 
        "Path": "/a28/", 
        "Arn": "arn:aws:iam::500238854089:role/a28/a28-streaming-access-role-st-StreamingAccessRole-14QHMTIOIRN5X"
    }
}
列出角色策略

$ aws iam list-role-policies --role-name a28-streaming-access-role-st-StreamingAccessRole-14QHMTIOIRN5X --region us-west-2 --profile aws-federated
{
    "PolicyNames": []
}
这意味着它甚至没有制定任何政策

aws iam list-policies --region us-west-2 --profile aws-federated | grep Stream-ConsumerOffset-RW-AccessPolicy
但是如果我在上面的示例中只提供了
kinesis:
语句,它将创建一个策略,但不能单独使用
dynamodb:


因此,我的问题是我应该如何使用一个cloudformation AWS::IAM::Role模板提供多个角色策略,或者这是特定于dynamodb的吗?

您的模板对我来说工作得非常好

我运行了您的模板,然后:

$ aws iam get-role --role-name stack1-StreamingAccessRole-1KDUTVG1OLLQM
{
    "Role": {
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17", 
            "Statement": [
                {
                    "Action": "sts:AssumeRole", 
                    "Effect": "Allow", 
                    "Principal": {
                        "Service": "ec2.amazonaws.com"
                    }
                }
            ]
        }, 
        "RoleId": "AROAJADV75HTIM6C62YXQ", 
        "CreateDate": "2017-04-08T22:22:21Z", 
        "RoleName": "stack1-StreamingAccessRole-1KDUTVG1OLLQM", 
        "Path": "/a28/", 
        "Arn": "arn:aws:iam::123456789012:role/a28/stack1-StreamingAccessRole-1KDUTVG1OLLQM"
    }
}
列出角色策略:

$ aws iam list-role-policies --role-name stack1-StreamingAccessRole-1KDUTVG1OLLQM
{
    "PolicyNames": [
        "Stream-ConsumerOffset-RW-AccessPolicy"
    ]
}
该策略作为内联策略附加,因此它不会出现在
列表策略
中。而是使用
get role policy
查看它:

$ aws iam get-role-policy --role-name stack1-StreamingAccessRole-1KDUTVG1OLLQM --policy-name Stream-ConsumerOffset-RW-AccessPolicy
{
    "RoleName": "stack1-StreamingAccessRole-1KDUTVG1OLLQM", 
    "PolicyDocument": {
        "Version": "2012-10-17", 
        "Statement": [
            {
                "Action": "kinesis:*", 
                "Resource": "arn:aws:kinesis:us-west-2:*:stream/a28-*", 
                "Effect": "Allow"
            }, 
            {
                "Action": "dynamodb:*", 
                "Resource": "arn:aws:dynamodb:us-west-2:*:table/a28-*", 
                "Effect": "Allow"
            }
        ]
    }, 
    "PolicyName": "Stream-ConsumerOffset-RW-AccessPolicy"
}

在角色中创建策略时,存在间歇性竞争条件。使用AWS::IAM::Policy单独创建策略,并将Roles属性设置为Role。问题将消失。

原因可能是比赛条件,正如Tim Bassett在中所回答的,我只是想添加最终有效的解决方案,以及如何添加到cloudformation

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Some Streaming api devops",
  "Parameters": {
    "environment": {
      "Type": "String",
      "Default": "staging",
      "Description": "environment"
    }
  },
  "Resources": {
    "StreamingAccessRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": "StreamingAccessRole",
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": [
                  "ec2.amazonaws.com"
                ]
              },
              "Action": [
                "sts:AssumeRole"
              ]
            }
          ]
        },
        "Path": "/a28/"
      }
    },
    "StreamConsumerOffsetRWAccessPolicy": {
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Action": [
                "cloudwatch:*"
              ],
              "Resource": [
                "*"
              ]
            },
            {
              "Effect": "Allow",
              "Action": "kinesis:*",
              "Resource": "arn:aws:kinesis:us-west-2:051620159240:stream/a28-*"
            },
            {
              "Effect": "Allow",
              "Action": [
                "dynamodb:BatchGetItem",
                "dynamodb:BatchWriteItem",
                "dynamodb:CreateTable",
                "dynamodb:DeleteItem",
                "dynamodb:DeleteTable",
                "dynamodb:DescribeLimits",
                "dynamodb:DescribeReservedCapacity",
                "dynamodb:DescribeReservedCapacityOfferings",
                "dynamodb:DescribeStream",
                "dynamodb:DescribeTable",
                "dynamodb:GetItem",
                "dynamodb:GetRecords",
                "dynamodb:GetShardIterator",
                "dynamodb:ListStreams",
                "dynamodb:ListTables",
                "dynamodb:PutItem",
                "dynamodb:Query",
                "dynamodb:Scan",
                "dynamodb:UpdateItem",
                "dynamodb:UpdateTable"
              ],
              "Resource": "arn:aws:dynamodb:us-west-2:051620159240:table/a28-*"
            },
            {
              "Action": [
                "sns:*Permission",
                "sns:Create*",
                "sns:Delete*",
                "sns:Publish",
                "sns:ReceiveMessage",
                "sns:Set*"
              ],
              "Resource": [
                "arn:aws:sns:us-west-2:051620159240:a28-*"
              ],
              "Effect": "Allow"
            }
          ]
        },
        "PolicyName": "StreamConsumerOffsetRWAccessPolicy",
        "Roles": [
          {
            "Ref": "StreamingAccessRole"
          }
        ]
      }
    }
  }
}

谢谢约翰的回答。我的公司账户发生了奇怪的事情。我也检查了aws用户界面,看到该策略一会儿就消失了。我已经尝试了好几天了,但是没有成功。我觉得在制定政策时有一些限制。你能给我建议一种调试为什么没有附加策略的方法吗
aws cloudformation描述堆栈事件——堆栈名称a28流式访问堆栈——区域us-west-2
不提供太多信息。它仅适用于
kinesis:
角色策略,但不适用于
dynamodb:
,这很奇怪。消失的资源表明CloudFormation模板正在被删除或回滚。检查是否仍然显示
CREATE\u COMPLETE
,并查看资源选项卡以检查已创建的内容。是的,状态仍然是
CREATE\u COMPLETE
。奇怪的是,它没有添加
dynamodb:
actions。但只适用于
kinesis:
。你听起来就像是一开始就制造了这个bug的人。我只是简单地尝试了一下dynamo政策,并提到了这个角色,它确实起到了作用,我会解决这个问题,然后看一看。谢谢你。我经历了很多痛苦才发现了它,AWS的支持人员也承认了这一点,并承认他们知道这一点,而且这一点并不重要。似乎这些类型的错误在AWS生态系统中很普遍(