Beanstalkd on AWS Elastic Beanstalk

If you’re not familiar with Beanstalkd, you probably should be.  It’s an awesomely fast, simple to use, zero-config (configuration is optional) work queue.  I use it with Laravel, but it works equally well for other tasks as well.  We recently deployed a Laravel application to AWS Elastic Beanstalk and needed to run Beanstalkd on the EC2 instances that would be spun up.  Here’s a short gist that will get you up and running with Beanstalkd in no time.  Just add this file to your .ebextensions folder and you’re all set!

  • jhdocker

    where is the .ebextensions folder in the ec2 instance?

    • Matt Zuba

      It’s not on the instance. You create a .ebextensions folder in the root of your zip file for your application and AWS processes it when the zip is deployed to an instance, after which it is deleted from the extracted directory.

      An example directory structure from a Laravel4 project of mine:

      .
      ├── app
      ├── bootstrap
      ├── bower_components
      ├── .ebextensions
      ├── .hg
      ├── .idea
      ├── node_modules
      ├── public
      └── vendor

      • jhdocker

        ok, so installing beanstalkd is actually in the application and not on the ec2
        server?

        • Matt Zuba

          Not really. The AWS Deployment Process extracts the .ebextensions files and runs the commands or instructions contained in them. In this specific case, the beanstalkd.config file is extracted on the EC2 instance, which instructs the deployment process to download beanstalkd v1.10, make it, install it and set it up as an upstart service.

  • Innokenty Longway

    Thanks, man!

  • ken

    Hi, do you have any plans on a tutorial for your full laravel to elastic beanstalk production workflow? I am new to laravel and I am trying to launch my site, locally hosted on homestead, to elastic beanstalk. There are less than a handful of tutorials out there that dig into this topic.

  • Roger Yu

    Hi Matt, I could not find the config file link here, was it removed?

    • Matt Zuba

      Hi Roger, it’s embedded directly in the page. Make sure you don’t have any script blockers turned on our anything from Github blocked.

      • Roger Yu

        I don’t have blocker, not sure what you mean by embedded directly in the page
        is it not a link in the above text?

        • Matt Zuba

          There’s a gist code block embedded from Github at the bottom of the text, right above the comments with the contents of what should be the .config file.

          Here’s a link to the gist: https://gist.github.com/mattzuba/507765a4370b2a220107#file-beanstalkd-config

          • Roger Yu

            see it now, thanks!

            how did beanstalkd store the queue message? is that persistent and could avoid loss when the aws node is shutdown?

          • Matt Zuba

            We didn’t have a need for that for our use case so I’ve never looked into how to possibly manage that. If you need persistence though, I’d use something like Iron MQ or AWS’s own queuing service.