Share Your AWS re:Post Experience - Quick 3 Question Survey
Help us improve AWS re:Post! We're interested in understanding how you use re:Post and its impact on your AWS journey. Please take a moment to complete our brief 3-question survey.
How do I troubleshoot issues related to scheduled tasks in Amazon ECS?
I scheduled my Amazon Elastic Container Service (Amazon ECS) task to run periodically. However, my Amazon ECS task isn't activated, and I don't get run logs or the history of the tasks in the cluster.
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
When you use a scheduled task, Amazon EventBridge calls the RunTask API for Amazon ECS to run the tasks on your behalf. Your scheduled Amazon ECS task might not be invoked because of the following reasons:
- You incorrectly configured the EventBridge time or cron expression.
- The EventBridge rule or schedule doesn't invoke the target.
- The RunTask API failed to run.
- The container instance exited because of application issues or resource constraints.
- The scheduled tasks failed because of capacity constraints.
- The scheduled tasks failed because of network connectivity issues.
Confirm that the EventBridge cron expression is configured correctly
To get the EventBridge cron expression, run one of the following AWS CLI commands.
If you use EventBridge rules, then run the describe-rule command:
aws events describe-rule --name example-rule --region example-region
If you use EventBridge Scheduler, then run the get-schedule command:
aws scheduler get-schedule --name example-schedule --region example-region
Note: Replace example-rule with your rule name, example-schedule with your schedule name, and example-region with your AWS Region.
In the command's output, check the EventBridge cron expression in the ScheduleExpression parameter. Make sure that you set the rule schedule to the UTC+0 time zone.
Check whether the rule or schedule doesn't invoke the target
To check the Invocations and FailedInvocations Amazon CloudWatch metrics for the EventBridge rule, complete the following steps:
- Open the CloudWatch console.
- In the navigation pane, choose Metrics, and then choose All metrics.
- Choose Events.
- Choose By Rule Name.
- Select TriggerRules, Invocations, and FailedInvocations for the EventBridge rule that runs the Amazon ECS task.
- Choose the Graphed metrics tab.
- For Statistic, select SUM for each metric .
To check the performance of the EventBridge Scheduler, review the InvocationAttemptCount, TargetErrorCount, and InvocationDroppedCount CloudWatch metrics.
If you see FailedInvocations or InvocationDroppedCount data, then verify that the EventBridge AWS Identity and Access Management (IAM) role has permission to invoke your task.
If you see TargetErrorCount data, then there's an issue with the target invocation. Check whether your task started, started and immediately failed, or didn't complete.
Check whether the RunTask action failed
Complete the following steps:
- Open the AWS CloudTrail console.
- In the navigation pane, choose Event history.
- For Lookup attributes, select Event name.
- For Enter an event name, enter "run task".
- In the time range filter, select the times that you expected your scheduled Amazon ECS task to run.
- In the table, select the event that you want to view.
- In the JSON event records, check for errorMessage or responseElements.failures.reason to confirm that the API didn't invoke the scheduled task.
Note: You can find the task ID for the failed task in the responseElements.tasks.taskARN field. - Troubleshoot the API failure.
Check whether the container exited after the task ran
Even after the task successfully runs, Amazon ECS tasks might stop because of application issues or resource constraints. To resolve this issue, see How do I troubleshoot Amazon ECS tasks that stop or fail to start when my container exits?
Check for capacity constraint issues
Capacity constraint issues that cause tasks to fail occur when your cluster doesn't have enough compute resources, such as CPU and memory. Or, the issues occur when other workloads that are running on the same cluster cause high resource usage. Restrictive task placement constraints or strategies might also reduce your available resources.
To monitor your resource usage, set up Container Insights on your Amazon ECS clusters. You can also set up CloudWatch alarms to notify you when you reach a resource usage threshold. To make sure that resources are available when you need them, set CPU and memory reservations for tasks. You might need to increase the desired count for the Amazon ECS service to scale out the cluster, or use cluster auto scaling.
Review existing task placement constraints, and adjust them to be less restrictive. It's a best practice to prioritize critical workloads, reschedule non-essential workloads, and test different placement strategies, such as spread, binpack, or random.
Use Amazon ECS capacity providers to reserve capacity for important workloads. It's a best practice to use Amazon Elastic Compute Cloud (Amazon EC2) Dedicated Instances for workloads that require isolated hardware. Use AWS Fargate for tasks that require available resources.
Check for network connectivity issues
To troubleshoot network connectivity issues for scheduled tasks, take the following actions:
- Make sure that the security group and network access control list (network ACL) rules allow the required inbound and outbound traffic for your tasks.
- Check that you correctly configured the internet gateway or NAT gateway for your virtual private cloud (VPC).
- Check your gateway route tables.
- Review your task definitions for environment variables with hardcoded IP addresses or hostnames. Make sure that existing IP addresses or hostnames are correct, and you can reach them.
To test network connectivity from your container instances, complete the following steps:
- Use SSH to connect to your Amazon EC2 instance.
- To remotely run commands on your container, run the following execute-command command:
Note: Replace cluster-name with your cluster name, task-id with your task ID, and container-name with your container instance name.aws ecs execute-command --cluster cluster-name --task task-id --container container-name --command "/bin/bash" --interactive
- To test connectivity, run one of the following commands:
-or-curl -v http://example.com
-or-nslookup example.com
Note: Replace example.com with your domain.nc -zv example.com 80
- Check the DNS resolution and routing to identify network issues.
To simplify connectivity, run tasks on Fargate instead of Amazon EC2. With Fargate, you don't need to manage the underlying infrastructure. Or, use VPC endpoints to connect to services without an internet gateway, NAT device, VPN connection, or AWS Direct Connect connection.

Relevant content
- asked 2 years agolg...
- asked 11 days agolg...
- asked 3 years agolg...
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 6 months ago