0

I have 2 EC2 instances - on one is the production app, on the other one is Redis. I connect from the first one to Redis.

This is how I set Sidekiq:

Sidekiq.configure_server do |config|
    config.redis = { url:       "redis://deployer_redis@PUBLIC_IP:6379/#{env_num}", 
                     namespace: "rails_app_#{Rails.env}" }
  end

  Sidekiq.configure_client do |config|
    config.redis = { url:       "redis://deployer_redis@PUBLIC_IP:6379/#{env_num}", 
                     namespace: "rails_app_#{Rails.env}" }
  end

When I do restart the Redis instance, the PUBLIC_IP will be different and the Rails app will not be able to connect to Redis.

I tried to use the PRIVATE_IP instead of the PUBLIC_IP (as PRIVATE_IP doesn't change while ), but it didn't work. There were no errors, but simply the jobs were not processed.

What's the recommended way to set the IP of EC2 instances in applications?

EDIT:

Also, when I ssh to the server, which IP should I use?

1 Answer 1

2

If you use ElastiCache with Redis then you should use DNS of your cluster. It usually looks like this redis.j5k8wa.0001.use1.cache.amazonaws.com and you can get it from your node configuration. Amazon recommends creating CNAME record in your DNS as an alias to the name provided by them.

If you run Redis on your own instance then the easiest way is using private static IP address for it. Another alternative is using dynamic DNS but this setup is fragile because of DNS propagation latency.

Update: Using Elastic IP would be your third option but using public IP address for internal communications between your app and Redis is not very secure and it is wasteful.

6
  • I am using the second option. So I should get Elastic IP for the Redis instance and then use this Elastic IP in the Rails app?
    – user984621
    Apr 8, 2016 at 17:46
  • Elastic IP would be third option but it is not the same as private static ip. It looks like you are using public addresses to access your instance it is not very secure. So, I would recommend assigning private static IP to the instance and then to use it in the connect string.
    – dtoubelis
    Apr 8, 2016 at 17:49
  • And this private IP address would be tied to the EC2 instance as long as the instance is live (= as long as the instance is not deleted)? Also, restarts of the instance doesn't change this address? (I am new to the AWS structure)
    – user984621
    Apr 8, 2016 at 17:52
  • Btw, when I click on my EC2 instance, I see Private IPs 172.31.XX.YYY. But when I tried to set this IP to the Rails app, it didn't work (probably the Rails app couldn't access this IP and for such apps is accessibly only on the public IP?)
    – user984621
    Apr 8, 2016 at 17:54
  • You always have option to specify private static IP for instance instead of amazon assigning you a random one if you are using VPC. If you need to restart instance the address will be preserved. If you terminate and start a new one - just specify the same address.
    – dtoubelis
    Apr 8, 2016 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .