我目前正在使用IAmazonECS.RunTaskAsync API立即在ECS上运行任务。现在,我想将其推迟到将来的某个时刻。根据文档,它应该是可能的,但我还没有办法做到这一点。
答案 0 :(得分:1)
您可以使用Amazon.CloudWatchEvents命名空间中的CloudWatchEvents。
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