Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to structure AWS Elastic Beanstalk production and staging environments with web and worker tiers?

I'm planning on transfer an application from Heroku to AWS Elastic Beanstalk. On the Heroku, I have two different applications, one for staging and the other for production, and both have their web and workers dynos.

I'd like to setup something like that on AWS EB. I've read the difference about Web Tier and Worker Tier, but here goes some questions:

Do I setup two different applications for production and staging? Or the same application and two different environments? If so, I would have to create 4 environments, two for production web/worker and two for staging web/worker? What's the correct structure? I'll use the same Rails application for web and worker. In that case, will I have to deploy them separate or is there a command to deploy both environments together?

like image 498
Ricardo Nacif Avatar asked Jul 01 '15 17:07

Ricardo Nacif


People also ask

What two types of environments can be created when using Elastic Beanstalk?

In AWS Elastic Beanstalk, you can create a load-balanced, scalable environment or a single-instance environment. The type of environment that you require depends on the application that you deploy.

How is the worker environment different from the webserver environment in Elastic Beanstalk?

The most important difference in my opinion is that worker tier instances do not run web server processes (apache, nginx, etc). As such, they do not directly respond to customer requests. Instead, they can be used to offload long-running processes from your web tier. The tiers communicate with each other via SQS.


2 Answers

I'll use the same Rails application for web and worker.

This tells me that you should have a single application. Applications manage application versions, which is basically just deployment history.

You will want to create 4 environments. This allows you to "promote to prod" by cname swapping, or by deploying a previously deployed version.

You will have to deploy your web/worker separately, but you could very easily create a script that deploys to both at the same time.

like image 150
Nick Humrich Avatar answered Oct 05 '22 06:10

Nick Humrich


For future reference, AWS Elastic Beanstalk later has created a solution for that called Environment Links:

https://aws.amazon.com/about-aws/whats-new/2015/11/aws-elastic-beanstalk-adds-support-for-environment-links/

With that feature, we're now able to link both environments with the same code (so we deploy it only once instead of twice). To make the worker run the worker process and the web to run the web server, you can set different environment variables and customize the EB initialization scripts to check for those vars and run specific process.

like image 41
Ricardo Nacif Avatar answered Oct 05 '22 04:10

Ricardo Nacif