separate environment config elastic beanstalk - ruby-on-rails

I'm creating a rails app with both web and worker tier in elastic beanstalk.
It's normal to start up web environment with ELB settings inside ebextensions. But I cannot startup worker environment because it doesn't have ELB.
Is there any way to separate ebextensions for each environments without creating another branch for this?

Refer to this link second answer
https://forums.aws.amazon.com/message.jspa?messageID=685803

Related

Rails subdomains for different evironments

I have a rails app, that I am currently shifting to production. But I want to setup a subdomain such that,
if I goto :
dev.myapp.com , I reach the development environment & if I goto
prod.myapp.com , I reach the production environment
Will I have to use 2 instances for this purpose, or can this managed by one?
My servers are on AWS, and domain is managed by GoDaddy
You can definitely use both environments on the same server but you would have to have 2 different instances running.
You can use nginx or Apache HTTPD to route the different domains (or sub-domains) to the actual instance running on your server (if it's an AWS EC2).
You have several other ways to configure it depending on your setup.
You'll need separate instances of the application running; the choice of running environment is a global, boot-time decision, with wide-ranging effects.
It's totally possible to run both of those application instances on the same server (AWS EC2 instance)... though it's more traditional to run the development mode on a local development machine, safely distanced from production.

How to automatically start a RubyOnRails app on server startup" (hopefully with more details about environment and nginx logs)?

I am having troubles with auto-scaling group in AWS. I am running a Ruby on Rails App in EC2 instance with ELB. I applied auto-scaling group so it scales-up automatically when heavy traffics come. However, the app server upon nginx does not start automatically so it becomes "OutOfService" in ELB. Any solution?
You can either use Monit to monitor your services, in this case Nginx and/or ( Puma, Unicorn, Passenger etc.. ) or use unix's own 'service' for things like this, Upstart.
https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples#auto-starting-services-with-upstart

Link RDS database of web tier environment to the worker tier environment elasticbeans

I'm struggling with my web application that I successfully deployed on AWS. Everything is working correctly on the web tier environment. However I have to add a worker tier environment to schedule background tasks.
So now I have 2 environment for my AWS application. One that is a web tier and the other that is a worker tier. I didn't create a database for the worker tier because I want this environment to use the RDS database of the Web tier.
How can I specify to the worker tier to use the RDS database of the web tier ?
Elastic Beanstalk is not really the best solution for handling RDS far as I know. Having RDS instance tied to your ElasticBeanstalk environment will work well for dev/test, however tying the lifecycle of the database instance to the lifecycle of your application's environment is not really the best option.
I would recommend simply decoupling RDS and not adding it to ElasticBeanstalk, handle it separately. This approach will allow you to connect multiple environments to RDS instance, terminate an environment without affecting the database lifecycle, and perform continuous updates with blue/green deployment method approach.
You can pass DB details (host, port, user, password) as environment variables to your ElasticBeanstalk applications (might be problematic because of security risks).
Another alternative is to store connection string in S3 bucket that you control and allowing your EC2 instances access this S3 bucket via EC2 instance profiles.
You can find more information and examples how to handle this in Using Elastic Beanstalk with Amazon RDS docs.
If above doesn't work for you then it's probably time to look into CloudFormation to manage your application lifecycle, infrastructure and dependencies in a more controlled fashion.

how to disable sqs on elastic beanstalk

I have a rails app on AWS Elastic Beanstalk. I process background tasks using delayed_job. I set up an eb worker instance to handle this. It works but shows as failed (red) in the dashboard. I believe this is because of the following error that I get every few seconds:
error: AWS::SQS::Errors::AccessDenied: Access to the resource https://sqs.us-west-2.amazonaws.com/xxx...xxxx is denied
I tried to remove sqs by means of the following to no avail:
services:
sysvinit:
aws-sqsd:
enabled: false
ensureRunning: false
How do I stop sqs? Ideally it would never be installed in the first place. If I can't modify the install configuration is there a way to prevent this error from affecting the status of my environment?
You are launching a worker tier environment. That is why SQS is being created for your environment. You should launch a "Web Server" environment if you do not want to launch a worker environment. Worker Tier environment in Elastic Beanstalk allows you to poll messages from an SQS queue periodically.
Read more about worker tier environments here:
http://aws.amazon.com/blogs/aws/background-task-handling-for-aws-elastic-beanstalk/
Read more about environment tiers here:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features-managing-env-tiers.html
If you want to use a Worker Tier environment with SQS enabled you can get rid of the AccessDenied exception by giving access to the IAM instance profile to access SQS as explained here:
https://stackoverflow.com/a/24880344/161628

Deploying Rails App to AWS Elastic Beanstalk, time out

I have an existing app that runs fine on localhost. I tried to deploy it to AWS Elastic Beanstalk today via the step-by-step instructions on this page
After using git aws.push to deploy it onto AWS, I wait for the status of the environment to go to green, and try to access the url it gives me. I get a timeout error after a long while of waiting.
I know this is really not much to go off of, but I'm equally stumped. Is there some kind of server side error log or console log (similar to what I see when I 'rails s' on my computer) so I can see what the AWS environment is writing out? I'm not even sure where to start debugging here.
Your first step is to snapshot your logs from the logs tab of your elastic beanstalk's environment you deployed to. This will give you a snapshot of the recent log activity. If you do need to ssh into the EC2 instance that backs your Elastic Beanstalk instance, it's not immediately evident how to do that. You first need to generate a key pair and download it something like my-key.pem. Then associate that key with the Elastic beanstalk application by editing the configuration and on the first tab, add my-key (note it's just the name, not the actual key). To ssh into your EC2 instance you use ssh -i /path/to/my-key.pem ec2-user#
You get the ec2 public url from the ec2 console. Hope all this helps.
First you'll need to ssh into your server
https://stackoverflow.com/a/4921866/274695
Then, you can look your application logs (passenger.log, production.log) at /var/app/support/logs/

Resources