I am currently using the IAmazonECS.RunTaskAsync API to run a task on ECS immediately. Now, I would like to postpone it to some point in the future. According to the documentation, it should be possible, but I haven't found a way to do it.
Asked
Active
Viewed 389 times
1
-
1Could you quote the documentation and provide the link? – Sergey Kovalev May 18 '18 at 10:49
-
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduling_tasks.html – Ricardo Peres May 18 '18 at 11:29
-
@RicardoPeres can you share your code for starting an ECS task please, I can't find any examples online – Farhad-Taran Apr 17 '19 at 19:16
1 Answers
1
You can use CloudWatchEvents from Amazon.CloudWatchEvents namespace for that.
var putRuleRequest = new PutRuleRequest
{
Name = "test",
RoleArn = "IAM_ROLE_ARN",
ScheduleExpression = "rate(5 minutes)",
State = RuleState.ENABLED,
};
var putRuleResponse = client.PutRuleAsync(putRuleRequest).Result;
var putTargets = new PutTargetsRequest()
{
Rule = putRuleResponse.RuleArn,
Targets =
{
new Target
{
Arn = "cluster arn",
RoleArn = "ecs events role",
EcsParameters = new EcsParameters
{
TaskDefinitionArn = "arn for the task definition",
TaskCount = 1
}
}
}
};
var response = await client.PutTargetsAsync(putTargets);
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

joaofs
- 486
- 1
- 7
- 17
-
What about passing parameters to the task definition (environment args) like we do with RunTaskRequest.Overrides ? – Ricardo Peres May 18 '18 at 15:08
-