我有两个AWS CloudFormation堆栈,一个是IAM角色,另一个是使用CloudFormation创建AWS服务并将相应角色导入其中的堆栈。
当部署10个或更多服务时,随机出现以下错误中的1或2个服务-
"AWS::ECS::Service service Unable to assume role and validate the listeners configured on your load balancer. Please verify that the ECS service role being passed has the proper permissions."
如果拆除所有服务并将服务重新部署到ECS集群,则该错误会出现,但是对于不同的服务而言。
AWS的解决方法可以在此处here看到。
如果拆除1或2个损坏的服务并重新部署服务,则服务将无问题地部署。因此,该问题似乎仅在同时部署许多服务时才会发生-这表明它可能是Cloudformation中IAM传播时间问题。
我尝试在服务定义中添加了depends on,
当部署10个或更多服务时,随机出现以下错误中的1或2个服务-
"AWS::ECS::Service service Unable to assume role and validate the listeners configured on your load balancer. Please verify that the ECS service role being passed has the proper permissions."
如果拆除所有服务并将服务重新部署到ECS集群,则该错误会出现,但是对于不同的服务而言。
AWS的解决方法可以在此处here看到。
如果拆除1或2个损坏的服务并重新部署服务,则服务将无问题地部署。因此,该问题似乎仅在同时部署许多服务时才会发生-这表明它可能是Cloudformation中IAM传播时间问题。
我尝试在服务定义中添加了depends on,
"service" : {
"Type" : "AWS::ECS::Service",
"DependsOn" : [
"taskdefinition",
"ECSServiceRole"
],
"Properties" : {
"Cluster" : { "Ref": "ECSCluster"},
"Role" : {"Ref" : "ECSServiceRole"},
etc...
}
}
但这不起作用。
正如您所注意到的,我还删除了ECSServiceRole的IAM导入值,并将其替换为内联资源策略,如下所示 -
"ECSServiceRole" : {
"Type" : "AWS::IAM::Role",
"Properties" : {
"AssumeRolePolicyDocument" : {
"Statement" : [
{
"Sid": "",
"Effect" : "Allow",
"Principal" : {
"Service" : [
"ecs.amazonaws.com"
]
},
"Action" : [
"sts:AssumeRole"
]
}
]
},
"Path" : "/",
"Policies" : [
{
"PolicyName" : "ecs-service",
"PolicyDocument" : {
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"ec2:Describe*",
"ec2:AuthorizeSecurityGroupIngress",
"elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
"elasticloadbalancing:DeregisterTargets",
"elasticloadbalancing:Describe*",
"elasticloadbalancing:RegisterInstancesWithLoadBalancer",
"elasticloadbalancing:RegisterTargets",
"sns:*"
],
"Resource" : "*"
}
]
}
}
]
}
}
但是,内联策略也无法解决问题。
有任何想法或指针将不胜感激!
回复第一个答案。
谢谢 - 我不知道这个改进。
这是关联 ECS 的服务链接角色的正确方式吗?
"ECSServiceRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"ecs.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "CreateServiceLinkedRoleForECS",
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:CreateServiceLinkedRole",
"iam:PutRolePolicy",
"iam:UpdateRoleDescription",
"iam:DeleteServiceLinkedRole",
"iam:GetServiceLinkedRoleDeletionStatus"
],
"Resource": "arn:aws:iam::*:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS*",
"Condition": {
"StringLike": {
"iam:AWSServiceName": "ecs.amazonaws.com"
}
}
}
]
}
}
]
}
}
最终答案
经过数月与AWS有关此事的断断续续的问题,AWS回复说他们在ELB后台对我们进行了限制。这就是为什么在同时通过Cloudformation部署3个以上的docker服务时会出现随机和不同的问题。解决方案与IAM权限无关,而是通过“AWS服务团队”增加ELB上的速率限制。
无法假定角色并验证指定的targetGroupArn。请验证传递的ECS服务角色是否具有适当的权限。(服务:AmazonECS;状态码:400;错误代码:InvalidParameterException;请求ID:...)
”。能问一下您增加了哪个ELB服务速率限制吗? - Lee Netherton