I've created the taskDefinition
using cloudformation and in the ContainerDefinitions
I have Command
to run the application with daily
as parameter.
TaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
:
:
ContainerDefinitions:
- Name: test-report
:
:
Command:
- "./test_report"
- daily
And I will want to create TaskSchedule
for different frequency (eg. daily, weekly, monthly etc).
I know that in the AWS console I can go to Edit Scheduled Task
> Schedule Targets
> Container override
and update the command override
with ./test_report, weekly
.
But how to override command in cloudformation taskSchedule? Is that something to do in Targets
property??
TaskSchedule:
Type: AWS::Events::Rule
Properties:
:
Targets:
Thanks in advance
@toske's answer is now out-of-date. You can set container overrides using the Input
parameter to the target. For example:
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:
....
Within cloudformation template, CloudWatch event rule schedule is defined using cron expressions (or alternatively rate expressions). You can't override entrypoint from the rule itself, but you can create task definition for each of the report types (frequencies). I was unable to find task command override in the UI or the cloudformation documentation.
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
You can read more on event rule expressions on amazon documentation website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With