Running an ECS Task on a Schedule With .NET

蹲街弑〆低调 提交于 2019-12-24 10:59:53

问题


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.


回答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



来源:https://stackoverflow.com/questions/50409411/running-an-ecs-task-on-a-schedule-with-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!