16

Recently I just started using AWS ElastiCache for a Laravel application. The application is running on 2 instances behind a ELB and handles about 6-10 request/second. Everything was going fine when I launched the application but then I started to receiving connection errors to the application with high latency and timeouts. The error messages was as follows:

[2016-05-17 07:28:25] production.ERROR: exception 'RuntimeException' with message 'Could not establish Memcached connection.' in /srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector.php:38 Stack trace: 
#0/srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(164): Illuminate\Cache\MemcachedConnector->connect(Array)
#1 /srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(102): Illuminate\Cache\CacheManager->createMemcachedDriver(Array) #2 /srv/ensemble/laravel/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(77): Illuminate\Cache\CacheManager->resolve('memcached')...

For my setup I'am using:

  • Laravel 5.2
  • AWS ElastiCache t2.small
  • php5-memcached module libmemcached 1.0.18

To solve my issue for the time being I have installed memcached on a separate EC2 instance and have had no issues.

My question is, do I need to use AWS ElastiCache PHP Client instead of the php5-memcached to use Elasticache? I was under the impression that Elasticache was a drop in replacement for Memcached and could be used with out a problem.

Thank you for the help!

6
  • did you tried it with the aws lib if it works? Commented May 18, 2016 at 17:12
  • Hi did u find anything related to this issue? Having similar issue Commented Apr 28, 2017 at 8:09
  • 1
    @SauminiNavaratnam - Unfortunately I haven't. But this issue has become almost non-existent in the last couple of months. I've had excellent stability and connection for a while now. I would recommend installing the AWS Elasticache PHP Client on your server too. Commented Apr 28, 2017 at 15:22
  • I think your firewall on aws might block the request, try first with a rule allow all request ingress and egress on both server, elb and memcached, if it's working, then you can revert back and check each one to know which firewall rule is causing problem Commented Feb 13, 2018 at 5:32
  • Check the security group. If someone set the access to the Elasticache only for a bunch of IPs and the connection is not open to the world (0.0.0.0/32), you can't access the service without a tunnel. Commented Oct 23, 2018 at 11:05

3 Answers 3

2

There are few important consideration when using manage services in AWS such as Elasticache.

  1. By default AWS Elasticache is not publicly accessible. Accesible only through Internal IP. (But there are work arounds for public access options like VPN connection, Direct Connect, basion host etc.)
  2. Elasticache offers no security e.g. password(that is why it's important to restrict it using network Nacl or application later Security Group)

Regarding your issue, the application cannot established connection to the cache instance, this error shows that the problem occurs somewhere in the network. This issue is very common.

And most likely caused by

  1. The EC2 instance doesn't have routes that can be used to access the elasticache endpoint. This issue occurs if you provisioned the Elasticache from a different VPC (different from VPC used by your application EC2). To solve this you either move the cache to the same VPC where the EC2 reside or You need to Peer the 2 VPC and create local route to establish connection.

  2. The EC2 instance has the valid route or they are in the same VPC however it's blocked by Elasticache SecurityGroup(SG). To solve this you need to check whether your EC2 Private IP is listed to Elasticache SG inbound rules with the memcache port. allow IP 172.0.1.1/32 to port 11211

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

Other than VPC and Security Group settings mentioned earlier by @Edcel, уоu need to check if Encryption in transit is enabled. In some Memcached servers offered by AWS уоu cannot disabled encryption, such as the serverless option. You can disable it by creating your own Memcached setup.

For servers that have Encryption in transit enabled, you'll need to use the Amazon ElastiCache Cluster Client and enable TLS by setting Memcached::OPT_USE_TLS => 1.

Comments

-2

Check what your security group settings are and set them to 0.0.0.0/32(not secure - open to everyone but a good way to test) then if that works just set it to your public ip address which you can find here https://www.whatismyip.com/what-is-my-public-ip-address/.

1 Comment

0.0.0.0/32 is a wrong cird for open to any ip. it should be 0.0.0.0/0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.