Reputation: 135
I didnt find in Amazon documentation what timezone launched ECS Fargate task use. Do you have any suggestions? I would like to use UTC everywhere.
Best regards, Maciej.
Upvotes: 5
Views: 17905
Reputation: 628
If you schedule your tasks to run via CloudWatch Scheduled Events, using scheduled expression or cron syntax, they're always launched in UTC time.
From the docs:
You can create rules that self-trigger on an automated schedule in CloudWatch Events using cron or rate expressions. All scheduled events use UTC time zone and the minimum precision for schedules is 1 minute.
For Example, the expression cron(30 9 * * ? *)
will launch your fargate task at 9:30 UTC
A rate expression would look like rate(1 minute)
or rate(1 hour)
create a rule in cloudwatch using the following command:
SCHEDULE_EXPRESSION='cron(30 9 * * ? *)'
aws events put-rule \
--name events-rule-tasks-name\
--schedule-expression "${SCHEDULE_EXPRESSION}" \
--description "Run every day at 09:30 UTC" \
--state "ENABLED" \
;
Create a target for this rule, i.e., define what this rule should invoke when the time matches the rule's rate/time value. set TaskDefinitionArn
value to invoke a fargate task, and specify launch type (FARGATE
) along with your other network config settings.
aws events put-targets \
--rule events-rule-tasks-${TASK_NAME} \
--targets '{"Arn":"arn:aws:ecs:'${AWS_REGION}':'${AWS_ACCOUNT_ID}':cluster/'${CLUSTER_NAME}'","EcsParameters":{"LaunchType":"FARGATE","NetworkConfiguration":'${NETWORK_CONFIGURATION}',"TaskCount": 1,"TaskDefinitionArn": "arn:aws:ecs:'${AWS_REGION}':'${AWS_ACCOUNT_ID}':task-definition/ecs-task-'${TASK_NAME}'"},"Id": "ecs-targets-'${TASK_NAME}'","RoleArn": "arn:aws:iam::'${AWS_ACCOUNT_ID}':role/ecsEventsRole"}' \
;
Upvotes: 2
Reputation: 1130
I hope by default the Task will in UTC, but that's my guess. In the Fargate world, we don't need to concern about the timezone the task gets launched as the underlying compute or host machine's timezone is not going to be honored by docker. Docker containers timezone works independently by the host machine configuration.
To set the required Timezone in your Containers you can set the Timezone in your Dockerfile using tzdata
and create a new Image.
RUN apt-get install -y tzdata
Pass the TZ
environment variable to the container in the Task definition when launching the ECS Task.
Upvotes: 3