我使用cloudformation创建了taskDefinition,并在ContainerDefinitions中让Command以daily作为参数运行应用程序。
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
:
:
ContainerDefinitions:
- Name: test-report
:
:
Command:
- "./test_report"
- daily我想要创建不同频率的TaskSchedule (例如,每日、每周、每月等)。
我知道在亚马逊网络服务控制台中,我可以转到Edit Scheduled Task > Schedule Targets > Container override并使用./test_report, weekly更新command override。
但是如何覆盖cloudformation中的命令呢?这是在Targets属性中做的事情吗??
TaskSchedule:
Type: AWS::Events::Rule
Properties:
:
Targets:提前感谢
发布于 2019-09-13 12:24:13
@toske的答案现在已经过期了。您可以使用目标的Input参数设置容器覆盖。例如:
LogicalResource:
Type: AWS::Events::Rule
Properties:
Description: "a scheduled task"
Name: my_scheduled_task
ScheduleExpression: "cron(* * * * ? *)"
State: ENABLED
RoleArn: !GetAtt MyRole.Arn
Targets:
- Id: fargate
Arn: !GetAtt MyCluster.Arn
RoleArn: !GetAtt MyTaskRole.Arn
Input: '{ "containerOverrides": [{"name": "container", "command": [ "python", "manage.py", "my_awesome_management_command", "-a" ]}]}'
EcsParameters:
....发布于 2018-06-26 11:07:11
在cloudformation模板中,使用cron表达式(或者CloudWatch表达式)定义cron事件规则时间表。您不能从规则本身覆盖入口点,但可以为每种报告类型(频率)创建任务定义。我在UI或cloudformation文档中找不到任务命令覆盖。
TaskDefinitionDaily:
Type: AWS::ECS::TaskDefinition
Properties:
# other task definition elements here
ContainerDefinitions:
# other container definitions here
Command:
- "./test_report"
- daily
TaskDefinitionWeekly:
Type: AWS::ECS::TaskDefinition
Properties:
# other task definition elements here
ContainerDefinitions:
# other container definitions here
Command:
- "./test_report"
- weekly
TaskDefinitionMonthly:
Type: AWS::ECS::TaskDefinition
Properties:
# other task definition elements here
ContainerDefinitions:
# other container definitions here
Command:
- "./test_report"
- monthly
# daily schedule at midnight UTC
ScheduledRuleDaily:
Type: "AWS::Events::Rule"
Properties:
Description: "ScheduledRule"
ScheduleExpression: "cron(00 00 * * ? *)"
State: "ENABLED"
Targets:
- Arn: !GetAtt
- MyCluster
- Arn
RoleArn: !GetAtt
- ECSTaskRole
- Arn
Id: id1
EcsParameters:
TaskCount: 1
TaskDefinitionArn: !Ref TaskDefinitionDaily
# weekly schedule at midnight UTC
ScheduledRuleWeekly:
Type: "AWS::Events::Rule"
Properties:
Description: "ScheduledRule"
ScheduleExpression: "cron(00 00 ? * 1 *)"
State: "ENABLED"
Targets:
- Arn: !GetAtt
- MyCluster
- Arn
RoleArn: !GetAtt
- ECSTaskRole
- Arn
Id: id1
EcsParameters:
TaskCount: 1
TaskDefinitionArn: !Ref TaskDefinitionWeekly
# monthly schedule at midnight UTC
ScheduledRuleMonthly:
Type: "AWS::Events::Rule"
Properties:
Description: "ScheduledRule"
ScheduleExpression: "cron(00 00 1 * ? *)"
State: "ENABLED"
Targets:
- Arn: !GetAtt
- MyCluster
- Arn
RoleArn: !GetAtt
- ECSTaskRole
- Arn
Id: id1
EcsParameters:
TaskCount: 1
TaskDefinitionArn: !Ref TaskDefinitionMonthly您可以在amazon documentation website上阅读有关事件规则表达式的更多信息。
https://stackoverflow.com/questions/51033944
复制相似问题