Configure httpd service timeout with Elastic Beanstalk

Viewed 1045

Intro

I have a worker environment setup with AWS Elastic Beantstalk. It is using the Apache proxy on a Linux 2 AMI. My worker environment occasionaly has to handle longer running tasks (around 120s).

Problem

I've noticed longer lasting tasks get resend to the SQS queue and thus are handled more then once. I've already taken care of the Visibility timeout and Inactivity timeout so that this would not happen, but the issue persists. After checking my logs at /var/log/httpd/access_log I noticed 504 errors on exaclty 60 seconds, telling me I somewhere hit another timeout.

Hacky solution

I was able to solve it by increasing the httpd Timeout from 60s to 120s by manually changing the value in /etc/httpd/conf/httpd.conf and restarting the httpd service.

The issue still comes back each time autoscaling happens or the server is restarted. The value gets reset to 60 seconds. What is needed is a way to set the timeout through configuration, bringing me to me actual question: How can i configure the httpd timeout setting with Elastic Beanstalk in a maintable way?

This article brought me so far, but the solution provided (using .ebextensions) seems to be for the deprecated Linux AMI (using linux 2).

What I've tried

I've read op on configuring the proxy here. I've tried all the following configurations, but it appears the configuration isn't being picked up at all.

Initial try:

~/workspace/my-app/
|-- .ebextensions
|   -- ....
|-- .platform
|   `-- httpd
|       `-- conf.d
|           `-- timeout.conf
`-- index.php

.platform/httpd/conf.d/timeout.conf

Timeout 120

Added 00_reload.config

based of this.

~/workspace/my-app/
|-- .ebextensions
|   -- ....
|-- .platform
|   `-- httpd
|       `-- conf.d
|           `-- timeout.conf
|   `-- 00_reload.config
`-- index.php

.platform/httpd/00_reload.config

container_commands:
   01_reload_httpd:
     command: "service httpd reload"

Overwrite the default apache config completely

if possible I would not like to do this as it becomes a maintenance nightmare.

~/workspace/my-app/
|-- .ebextensions
|   -- .....
|-- .platform
|   `-- httpd
|       `-- conf
|           `-- httpd.conf
`-- index.php

.platform/httpd/conf/httpd.conf

It's a complete copy of the default provided by AWS, but changed the Timout setting to 120.

# Managed by Elastic Beanstalk
PidFile /run/httpd.pid

Listen 80
User apache
Group apache
LogLevel warn
TraceEnable off
EnableSendfile on
AddDefaultCharset UTF-8

# Enable TCP keepalive
Timeout 120
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 60

Include conf.modules.d/*.conf
.....
1 Answers

It appears beanstalk assumes the .platform folder to be at the absolute root of your project. Mine was located inside my document root: /public/.platform/

The confusing started because the documentation showed it to be at the same level as the .ebextensions folder, which does need to be inside your document root (/public for me). There's also no mention about this anywhere.

Once I figured that out, the documentation of AWS was working perfectly. My final config below.

~/workspace/my-app/
|-- public
|   -- .ebextensions
|   -- index.php
|-- .platform
|   `-- httpd
|       `-- conf.d
|           `-- increase_timeout.conf

.platform/httpd/conf.d/timeout.conf

Timeout 120

I hope my struggles can be of help to someone down the line.

Related