Using Redis with Rails on Elastic Beanstalk - ruby-on-rails

I am trying to launch a rails API on AWS. I have created an Elastic Beanstalk app, created a PostgreSQL RDS, and setup CodePipeline, but when I try to deploy I get an error that says "CannotConnectError: Error connecting to Redis". My app uses Redis to cache user login certificates, and when I run it locally I just type "redis-server" in the terminal before "rails s" and it works like a charm. I have tried creating an ElastiCache instance, but I can't figure out how to connect it to my app. I'm also unsure of whether using ElastiCache for this might be overkill, and if it might instead be better to somehow configure the app to start running Redis without it when it's deployed. Another possible solution I can think of is if there a way for me to run terminal commands on my Elastic Beanstalk app and just deploy Redis manually?
I am having a lot of trouble finding a clear explanation of what I am supposed to do to setup Redis to work with Elastic Beanstalk. Can anyone help explain this, or point me to a good resource?

if there a way for me to run terminal commands on my Elastic Beanstalk app and just deploy Redis manually?
Yes, you can do this. EB allows you to write customization scripts through .ebextensions. Thus using it you could install and setup your local Redis server on the EB.
To install redis, the following 10_install_redis.config in your .ebextensions config file could be used:
commands:
10_install_redis:
command: amazon-linux-extras install -y redis4.0
You would have to build upon the above to further setup and customize the redis server to your needs.
However, running redis on your EB instance is not a very good practice. It would be better to have it outside of your EB environment, for example on a separate EC2 instance or ECS containers if you want to save up on cost as compared to running AWS managed ElastiCache.

Related

What is the best approach to create a schedule job on AWS Elastic Beanstalk - Ruby on Rails?

Recently I moved my personal project from Heroku to AWS ElasticBeanstalk, because of Heroku's new pricing table. There, in Heroku I had a schedule job using Sidekiq which was dependent of a Redis and Dynno worker.
I deployed my project at AWS, without the scheduled job, now I am facing some problems to create this cronjov at AWS.
What I've tried?
Create a cron job at my EC2 enviroment using a cron.config on the zip .ebextensions - I can even run some simple cronjobs, but I couldn't run a Ruby on Rails script because some configuration that is necessary and the documentation is not clear.
Tried to use the the active-elastic-job gem, but it raises a lot of gem problems, which makes it impossible to be deployed
Tried to use AWS Lambda, but I did not understand how to do it, saw many examples in Python and other languages, but not in Ruby
What do you suggest me to do?
My next approach would be to use create a cronjob in my EC2 instance with a http request to a controller containing the task I need ...
I ended up using the rufus-scheduler gem. It works fine with AWS Elastic Beanstalk and its EC2 instances.

The missing piece of the puzzle: how to run Rails C on an AWS ECS Fargate environment

Setting up a Rails app on AWS Fargate has been somewhat of a struggle, but the more I tried, the more I learned. I now have multiple tasks running multiple parts of my environment (websever, worker and a task queue). The last piece of the puzzle is establishing rails console access to this environment.
I've read articles on Medium: https://engineering.loyaltylion.com/running-an-interactive-console-on-amazon-ecs-c692f321b14d, but it seems to be depending on EC2 instead of Fargate.
Then I found this post on SO: How to launch a rails console in a Fargate container
It seems that the solution is to set-up a VPN into my VPC. Since I'm not an expert on networking, I was wondering if there is a clear guide on how to set-up a VPN to my VPN on Mac?
And if I finally succeed with setting up this VPN, how would I then be running rails c? Is there some AWS CLI command I need to run? Do I need to define a separate task that runs the command... or?
To run rails console on a container running on fargate, you would need to run a docker exec, but it is not supported yet. There is an open issue for this: https://github.com/aws/containers-roadmap/issues/187

best approach to deploy dockerized rails app on AWS?

I dockerized existing Rails Application and it runs on development properly. I want to deploy the app to production environment. I used docker-compose locally.
Application Stack is as follows:
Rails app
Background Workers for mails and cleanup
Relation DB - postgres
NoSQL DB - DynamoDB
SQS queues
Action Cable - Redis
Caching - Memcached
As far as I know, options for deployment are as below:
ECS (Trying this, but having difficulties in relating concepts such as Task and Task Definitions with docker-compose concepts)
ECS with Elastic Beanstalk
With Docker Machine according to this docker documentation: https://docs.docker.com/machine/drivers/aws/
I do not have experience with capistrano, haven't used it yet on this project yet so I am not aiming to use it for docker deployment either. I am planning to use some CD/CI solution for easy deployment. I want advice on options available, and how to deploy the stack in a way that is easy to maintain and push updates with minimal deployment efforts?

How to setup postgres with Kubernetes using Deis Workflow?

I am using Google container engine and Deis Workflow to run my rails application. I do not have a dockerfile, I just use Heroku buildpack.I was successfully able to deploy my app but I am not able to configure my database. I understand that my database cannot reside in my application, it has to be another service which will persist data. I am thinking of using AWS RDB and I think I will want to configure something like what is pointed here on heroku.
I am new to Kubernetes and this workflow, I would really appriciate if someone can point me out how to proceed and achieve this.
Have a look at the Helm Charts repository.
After installing Helm you can run:
helm install stable/postgresql

Can I use Docker for production deployment of a Rails application?

I want to use Docker to deploy my Rails application. I want to know if there is someone tried this? And what problems can I face?
Deploying Rails apps to production with Docker is not only possible, but something you'd want to do, to make sure your app runs on any server you deploy.
This comes with some challenges. First, it's advisable to run your database server and your Rails app different containers to keep things isolated. You can also set up your production server Docker environment with Docker Machine. Machine allows you to configure AWS, Digital Ocean, Azure and Compute Engine instances (among many others), and manage your containers from your computer. I assume you're just getting started with Docker, so I suggest you take a look at this cool guide about setting up a Rails + Postgres app with Docker.

Resources