Search code examples
ruby-on-railsherokumemcachedamazon-elasticache

Can I use Amazon Elasticache on Heroku?


I am currently using Heroku's Memcached in a Rails 3 app and would like to move over to Elasticache because the pricing is much more favorable. Is this possible? Is the configuration relatively straightforward? Is there anything that I should be aware of as regards the performance?


Solution

  • DANGER: I do NOT recommend using this solution for production use. While this does work, @btucker pointed out that it allows any Heroku-hosted app to access your ElastiCache cluster.

    Yes you can. The setup is similar to the guide Heroku has on Amazon RDS. The steps that differ go like this:

    1. Follow the "Get Started with Amazon ElastiCache" guide to create a cache cluster and node
    2. Install the ElastiCache Command Line Toolkit
    3. Allow Heroku's servers ingress to your ElastiCache cluster like the RDS guide explains but replace the rds- commands with elasticache- ones:

      elasticache-authorize-cache-security-group-ingress \
        --cache-security-group-name default \ 
        --ec2-security-group-name default \
        --ec2-security-group-owner-id 098166147350 \
      
        # If your AWS_CREDENTIAL_FILE environment setting is configured,
        # this option is not necessary.
        --aws-credential-file ../credential-file-path.template
      
    4. Set a Heroku config value for your production app with your cluster's hostname:

      heroku config:set MEMCACHE_SERVERS=elasticachehostname.amazonaws.com
      

    After that, follow the Memcache Rails setup, and you're set.