How to Increase Elastic Beanstalk Deployment Timeout for Long-Running .ebextensions Commands


1 views

When deploying applications to AWS Elastic Beanstalk, you might encounter timeout errors during the execution of lengthy .ebextensions commands, particularly during initial deployments or when performing resource-intensive operations like:

  • Cloning large Git repositories
  • Running complex database migrations
  • Processing large datasets
  • Compiling or building extensive dependencies

The default deployment timeout in Elastic Beanstalk is approximately 15 minutes, which might be insufficient for certain operations.

To extend the deployment timeout, you need to modify the AWS Elastic Beanstalk environment configuration. Here's how to do it programmatically:

Option 1: Using AWS CLI

aws elasticbeanstalk update-environment \
  --application-name YourAppName \
  --environment-name YourEnvName \
  --option-settings \
    Namespace=aws:elasticbeanstalk:command,OptionName=Timeout,Value=1800

Option 2: Using .ebextensions Configuration

Create or modify a configuration file in your .ebextensions directory (e.g., timeout.config):

option_settings:
  - namespace: aws:elasticbeanstalk:command
    option_name: Timeout
    value: 1800
  - namespace: aws:elasticbeanstalk:command
    option_name: DeploymentTimeout
    value: 1800

For particularly long-running operations, consider these additional optimizations:

option_settings:
  - namespace: aws:elasticbeanstalk:command
    option_name: Timeout
    value: 3600  # 60 minutes
  - namespace: aws:elasticbeanstalk:command
    option_name: DeploymentTimeout
    value: 3600
  - namespace: aws:elasticbeanstalk:command
    option_name: BatchSizeType
    value: Fixed
  - namespace: aws:elasticbeanstalk:command
    option_name: BatchSize
    value: 1

If your timeout issues are specifically related to cloning large repositories during deployment, consider these alternatives:

  1. Pre-build the application in your CI pipeline
  2. Use AWS CodeCommit instead of external repositories
  3. Implement a multi-stage deployment process

After applying these changes, you can verify the timeout settings:

aws elasticbeanstalk describe-configuration-settings \
  --application-name YourAppName \
  --environment-name YourEnvName \
  --query 'ConfigurationSettings[0].OptionSettings[?contains(Namespace,command) && (OptionName==Timeout || OptionName==DeploymentTimeout)]'

The output should show your updated timeout values in seconds.

  • Ensure you have sufficient instance resources (CPU/memory) for your operations
  • Check CloudWatch logs for specific command failures
  • Verify IAM permissions for the operations being performed
  • Consider breaking long-running commands into smaller scripts

When running complex initialization scripts through .ebextensions, especially those involving large git clones or resource-intensive setup commands, the default 600-second (10-minute) timeout often proves insufficient. The deployment fails with:

WARN The following instances have not responded in the allowed command
     timeout time (they might still finish eventually on their own).
INFO Command execution completed. Summary: [Successful: 0, TimedOut: 1].

Elastic Beanstalk provides the Timeout option in the aws:elasticbeanstalk:command namespace to control deployment timeouts. Create or modify your .ebextensions/01_timeout.config file:

option_settings:
  aws:elasticbeanstalk:command:
    Timeout: 1800

This extends the timeout to 1800 seconds (30 minutes). The value is specified in seconds and can be adjusted as needed.

For more granular control, consider these additional settings:

option_settings:
  aws:elasticbeanstalk:command:
    Timeout: 3600
    BatchSize: 1
    BatchSizeType: Percentage
    HealthCheckSuccessThreshold: Healthy

For particularly lengthy operations, consider these approaches:

  1. Split large git clones into multiple commands
  2. Use background processes with proper status files
  3. Implement a custom health check endpoint

Example of a background process pattern:

commands:
  long_running_process:
    command: |
      nohup /your/command.sh > /tmp/process.log 2>&1 & 
      echo $! > /var/run/process.pid
    test: "[ ! -f /var/run/process.done ]"

After deployment, verify the settings took effect:

aws elasticbeanstalk describe-configuration-settings \
  --application-name your-app-name \
  --environment-name your-env-name \
  --query "ConfigurationSettings[0].OptionSettings[?contains(Namespace, 'aws:elasticbeanstalk:command')]"
  • Changes might require an environment rebuild (not just restart)
  • Timeout values beyond 3600 seconds may require AWS support ticket
  • Monitor CloudWatch logs for Command Timeout messages

Remember to also check your instance type - underpowered instances may simply need more resources to complete operations faster.