Lambda logs end with `Task timed out after 3.00 seconds`.
BeginnerTroubleshootingECS, EKS, ECR and Lambda
Answer
Likely causes → The default timeout is 3 seconds. The function is slow, or it hangs on a network call: a VPC function with no route to the internet or endpoint, a DB connection without a timeout, or a downstream that is slow.
Diagnose →
aws lambda get-function-configuration --function-name orders-api --query '[Timeout,MemorySize,VpcConfig]'
aws logs tail /aws/lambda/orders-api --since 15m
# enable X-Ray active tracing to see which segment takes the time
Fix →
- Set client timeouts on every network call below the function timeout
- Raise the timeout to a realistic value:
aws lambda update-function-configuration --function-name orders-api --timeout 15 - Raising memory also gives more CPU, which speeds up CPU-bound code
Prevent → Alarm on the Duration p99 against the timeout, and turn on X-Ray tracing.
More on ECS, EKS, ECR and Lambda
`docker push 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4` fails with `no basic auth credentials` (or `denied: Your authorization token has expired. Reauthenticate and try again.`).BeginnerFargate tasks stop with `CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref ... dial tcp 52.x.x.x:443: i/o timeout`.Intermediate`ResourceInitializationError: unable to pull secrets or registry auth: ... AccessDeniedException: User: arn:aws:sts::111111111111:assumed-role/ecsTaskExecutionRole/... is not authorized to perform: secretsmanager:GetSecretValue`.IntermediateA task stops with `Essential container in task exited`, exit code 137, and reason `OutOfMemoryError: Container killed due to memory usage`.BeginnerThe ECS service event says `service api was unable to place a task because no container instance met all of its requirements. The closest matching container-instance ... has insufficient memory available.`IntermediateAn ECS deployment rolls back automatically, and the event says `deployment failed: tasks failed to start` from the circuit breaker.Advanced