Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecs): ECS drain hook can't change instance state to draining #3198

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -460,6 +458,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down Expand Up @@ -614,6 +635,37 @@
"EcsClusterDefaultAutoScalingGroupLifecycleHookDrainHookRoleA38EC83B"
]
},
"ScheduledEc2TaskScheduledEventRuleFE2376A2": {
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(1 minute)",
"State": "ENABLED",
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"EcsCluster97242B84",
"Arn"
]
},
"EcsParameters": {
"TaskCount": 2,
"TaskDefinitionArn": {
"Ref": "ScheduledEc2TaskScheduledTaskDef56328BA4"
}
},
"Id": "awsecsintegecsScheduledEc2TaskScheduledTaskDef18FB4348",
"Input": "{}",
"RoleArn": {
"Fn::GetAtt": [
"ScheduledEc2TaskScheduledTaskDefEventsRole64113C5F",
"Arn"
]
}
}
]
}
},
"ScheduledEc2TaskScheduledTaskDefTaskRoleC3FA127C": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down Expand Up @@ -829,37 +881,6 @@
}
]
}
},
"ScheduledEc2TaskScheduledEventRuleFE2376A2": {
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(1 minute)",
"State": "ENABLED",
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"EcsCluster97242B84",
"Arn"
]
},
"EcsParameters": {
"TaskCount": 2,
"TaskDefinitionArn": {
"Ref": "ScheduledEc2TaskScheduledTaskDef56328BA4"
}
},
"Id": "awsecsintegecsScheduledEc2TaskScheduledTaskDef18FB4348",
"Input": "{}",
"RoleArn": {
"Fn::GetAtt": [
"ScheduledEc2TaskScheduledTaskDefEventsRole64113C5F",
"Arn"
]
}
}
]
}
}
},
"Parameters": {
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-ecs/lib/drain-hook/instance-drain-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ export class InstanceDrainHook extends cdk.Construct {
actions: [
'ecs:ListContainerInstances',
'ecs:SubmitContainerStateChange',
'ecs:SubmitTaskStateChange',
'ecs:SubmitTaskStateChange'
],
resources: [props.cluster.clusterArn]
}));

fn.addToRolePolicy(new iam.PolicyStatement({
actions: [
'ecs:UpdateContainerInstancesState',
'ecs:ListTasks'
],
resources: [props.cluster.clusterArn]
resources: [`arn:aws:ecs:${cdk.Aws.REGION}:${cdk.Aws.ACCOUNT_ID}:container-instance/*`]
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -616,6 +614,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -637,6 +635,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -616,6 +614,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -616,6 +614,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -460,6 +458,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@
"Action": [
"ecs:ListContainerInstances",
"ecs:SubmitContainerStateChange",
"ecs:SubmitTaskStateChange",
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
"ecs:SubmitTaskStateChange"
],
"Effect": "Allow",
"Resource": {
Expand All @@ -260,6 +258,29 @@
"Arn"
]
}
},
{
"Action": [
"ecs:UpdateContainerInstancesState",
"ecs:ListTasks"
],
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:ecs:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":container-instance/*"
]
]
}
}
],
"Version": "2012-10-17"
Expand Down