Not found.

How to fix Elastic Load Balancer 408 Errors in Elastic Beanstalk

Recently, when viewing Apache logs for an application deployed in Elastic Beanstalk (EB) behind an Elastic Load Balancer (ELB), I noticed a frequently recurring 408 error being triggered by an internal connection.

The 408 error was caused because of a connection draining setting being enabled which in turn caused EB to think that requests were returning a 4xx error, thus triggering numerous alarms and actions.

Here’s a sample of what the logs looked like (-) - - [03/May/2016:22:08:51 +0000] "GET /status HTTP/1.1" 200 7 "-" "ELB-HealthChecker/1.0" (-) - - [03/May/2016:22:08:52 +0000] "GET /status HTTP/1.1" 200 7 "-" "ELB-HealthChecker/1.0" (-) - - [03/May/2016:22:09:13 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:13 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:17 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:17 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:17 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:17 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:17 +0000] "-" 408 - "-" "-" (-) - - [03/May/2016:22:09:17 +0000] "-" 408 - "-" "-"

Here is what I did to resolve the issue.

Continue Reading Article

How to Set S3 ContentType and Other Request Headers with Laravel Filesystem / Cloud Storage

Laravel 5 brought to the table a powerful Storage Facade that allowed developers to easily integrate any kind of storage system into an application.

Amazon S3, being a Laravel native supported Filesystem, makes it easy to upload large files directly from the application to cheap and reliable storage.

S3 supports many types of request headers when making PUT requests, the one I was specifically interested in was ContentType.

The application was uploading an audio file, the ContentType of which is audio/mpeg. The default configuration was uploading the file as octet/stream. This would cause a browser to download the file, whereas we needed the ability to play the file directly from the browser.

The solution, albeit undocumented, is pretty simple.

Continue Reading Article

How to Fix Laravel HTTPS Redirect Loop on Amazon Elastic Beanstalk/Load Balancer/Proxy

If you are forcing HTTPS on routes in Laravel but are having issues with a redirect loop and your app is behind a proxy, load balancer, or something like Elastic Beanstalk, try adding this to your .htaccess file:

#Fixes HTTPS Redirect Loop

Many load balancers will accept HTTPS traffic and forward it internally as HTTP but pass an environment variable stating that the traffic received at the load balancer/proxy was intended for HTTPs. What this line does is checks for that environment variable X-FORWARDED-PROTO and if it is set to HTTPS remaps the request to HTTPS behind the proxy or load balancer.

How to Get Laravel Task Scheduling Working on AWS Elastic Beanstalk Cron

We use AWS Elastic Beanstalk for quite a few projects and its’ rapid deployment models make it indispensable.

Laravel 5 (5.1) includes a powerful Task Scheduling model that can be used to automate any part of your Laravel application using just one cron that runs an artisan command.

If you’re setting environment variables directly through the Elastic Beanstalk console, there are a few tricks you’ll need to use to get Task Scheduling working properly with Elastic Beanstalk.

Continue Reading Article

Dynamically Generate and Replace HTML5 canvas Elements With img Elements

Overnight, Chrome was updated and broke an application feature we’ve deployed.

The application was dynamically drawing a signature into an HTML5 canvas element and the user would print the page, which contained the canvas. The printed (physical) document would contain the canvas containing the signature.

With the Chrome update, canvas elements are no longer being displayed on the printed output, physical or PDF.

Here is a quick snippet to quickly gather all canvas elements, dynamically generate an image, and replace the canvas elements with the new image. This fixed the issues with our application.

Continue Reading Article

Overload a Laravel Model’s __construct and save Methods

Here are a couple of quick snippets if you need the ability to overload a Model’s constructor or save methods.

Continue Reading Article

Clone an EC2 AMI to Another AWS Account

If you manage more than one AWS account, you most likely have pre-built AMIs that you frequently use when provisioning new instances.

You may be building AMIs on a per account basis, and some of these may be nearly identical to those found on the other accounts you manage. Effectively, you are duplicating effort when, with a bit of magic, you can easily clone/copy any AMI to another account.

Continue Reading Article

Serve Javascript/CSS with a Laravel Route

For a quick solution to serving up a Javascript or CSS file using Laravel routes, i.e. http://www.example.com/js-file, take a look at the following snippet.

Continue Reading Article

Resize a gp2 Backed EBS Volume on an HVM Instance in AWS EC2

Unlike PV instances in EC2, HVM instances run as if it were on the native hardware platform. HVM instances however do not support standard/magnetic backed EBS storage types. If you were used to using resize2fs for resizing your EC2 volumes, you’ve probably realized this doesn’t work with the new instance types.

Online resizing of a gp2/HVM volume can be performed nearly as quickly as standard/magnetic/PV volumes.

Continue Reading Article

Replace a Failing Drive in a RAID6 Array Using mdadm

Most users that run some sort of home storage server will probably, (see: hopefully), be running some type of RAID array.

It is also likely that at some point, one or more of the drives in your array will start to degrade. That could be read errors, bad sectors, or worse complete hardware failure. In this case you will have to replace the faulty drive with a new drive of equal or larger size.

I was experiencing read errors on a new 4TB Western Digital Red NAS drive. I have 6 of these drives in a RAID6 array running Ubuntu 13.10. The array was using mdadm as a software RAID controller.

Here you will find the steps taken to replace a failing drive within a RAID6 array that uses mdadm as a software RAID controller.

Continue Reading Article