DEV Community

Cover image for Solving AWS ECS connect timeouts: configure default settings easily
Siddhant Khare
Siddhant Khare

Posted on

Solving AWS ECS connect timeouts: configure default settings easily

If you've ever scratched your head over unexpected timeouts in your AWS ECS Service Connect applications, you're not alone. I recently faced a perplexing issue where my long-running processes kept timing out. After some digging, I discovered that the default request timeout for HTTP (including HTTPS and gRPC) in AWS ECS Service Connect is 15 seconds. This default setting can be a silent culprit causing disruptions, especially if you're unaware of it.

But here's the good news: as of January 2024, AWS now allows us to configure these timeout settings. Let's dive into how you can adjust them to suit your application's needs.


Understanding the default timeout behavior

Before the update, the request timeout was a fixed value of 15 seconds, and there was no way to change it. This meant that any process taking longer than 15 seconds would abruptly end, leading to frustrating errors and poor user experience.


The January 2024 Update: Configurable Timeouts

AWS listened to user feedback and, in January 2024, introduced the ability to configure timeout settings for ECS Service Connect. You can read more about this update in the official AWS announcement.


How to change the timeout settings

Prerequisites

  • AWS SDKs and AWS CLI: Ensure you have the latest versions installed. If not the latest, versions released after January 2024 will suffice.

Timeout parameters

There are two main timeout settings you can adjust:

  1. idleTimeoutSeconds: The amount of time (in seconds) before an idle connection is closed. The default is 300 seconds for TCP and 3600 seconds for protocols like HTTP.

  2. perRequestTimeoutSeconds: The maximum time (in seconds) allowed for each request. The default is 15 seconds.

Updating the service definition

To change the timeout settings, you need to modify your service definition JSON. Here's how you can specify the new timeout values:

{
  "serviceConnectConfiguration": {
    "services": [
      {
        "clientAliases": [
          {
            "port": 3000
          }
        ],
        "portName": "your-port-name",
        "timeout": {
          "idleTimeoutSeconds": 3600,
          "perRequestTimeoutSeconds": 3600
        }
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • clientAliases: Defines the ports your service listens on.
  • portName: The name of the port as defined in your task definition.
  • timeout: Contains the timeout settings.
    • idleTimeoutSeconds: Set to 3600 seconds (1 hour) in this example.
    • perRequestTimeoutSeconds: Also set to 3600 seconds.

You can adjust these values based on your application's requirements.


Applying the changes

Once you've updated the service definition, you can deploy the changes using your preferred method:

  • AWS CLI
  • CloudFormation
  • Third-party tools like ecspresso

Verifying the timeout settings

To confirm that your new timeout settings are in effect, you can use the AWS CLI:

aws ecs describe-services \
  --cluster your-cluster-name \
  --services your-service-name
Enter fullscreen mode Exit fullscreen mode

Note:

  • If you haven't set custom timeout values, the default timeout settings (15 seconds for perRequestTimeoutSeconds) won't appear in the output. This can be misleading, so it's essential to explicitly define the timeouts if your application requires longer durations.

Important considerations

  • No Upper Limit Documented: AWS doesn't specify an upper limit for these timeout settings. However, setting excessively long timeouts might not be the best solution.

  • Architecture Implications: If your tasks take a very long time to complete, it might cause issues during deployments or scaling. It's worth revisiting your application architecture to see if you can optimize performance or handle long-running tasks differently (e.g., using asynchronous processing or background jobs).


Conclusion

Default settings can sometimes trip us up, especially when they're not explicitly stated in configuration outputs. By being aware of the default 15-second request timeout in AWS ECS Service Connect and knowing how to adjust it, you can prevent unnecessary timeouts and ensure a smoother experience for your users.

Remember to keep your AWS SDKs and CLI updated, and always verify your settings after making changes. With these steps, you can take full control of your application's timeout behavior.


For more tips and insights, follow me on Twitter @Siddhant_K_code and stay updated with the latest & detailed tech content like this.

Top comments (0)