Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to ElastiCache cluster from AWS Lambda function

Is it possible to connect from an AWS Lambda function to a Redis ElastiCache cluster?

I can't figure out if it's a configuration problem or it's simply not possible.

PS: I made a test from an EC2 instance and I can connect to the Redis node. Also the Lambda function and the Redis node are in the same region.


UPDATE (09 Oct 2015):

Amazon announced VPC for AWS Lambda functions. Details here

This means we can now access any resource in AWS behind VPC security group, including ElastiCache and RDS machines.

UPDATE (11 Feb 2016): Amazon launched VPC for AWS Lambda.

https://aws.amazon.com/about-aws/whats-new/2016/02/access-resources-within-a-vpc-using-aws-lambda/

like image 487
Mircea Soaica Avatar asked Jan 03 '15 20:01

Mircea Soaica


People also ask

How do I access my ElastiCache cluster?

Sign in to the AWS Management Console and open the ElastiCache console at https://console.aws.amazon.com/elasticache/ . To see a list of your clusters running the Memcached engine, in the left navigation pane, choose Memcached.

Is Amazon ElastiCache serverless?

Integrating Amazon ElastiCache with other AWS services: The serverless way. Amazon ElastiCache for Redis is a great way to accelerate cloud applications through caching and other use cases such as session storage, leaderboards, and messaging.

How do I test my connection to an Amazon ElastiCache Redis or Memcached cluster?

ElastiCache supports both cluster mode disabled and cluster mode enabled Redis clusters. To test a connection to these clusters, you can use the redis-cli utility. The latest version of redis-cli also supports SSL/TLS for connecting to clusters with encryption and/or authentication turned on.

Can we use ElastiCache with DynamoDB?

ElastiCache for the win!AWS is offering in-memory stores allowing you to cache read requests to DynamoDB and other database systems: ElastiCache.


2 Answers

As of Feb 2016, AWS allows using lambda functions to connect to Elasticache. Refer to Access Resources within a VPC using AWS Lambda. Here is a link how it works - Tutorial: Configuring a Lambda Function to Access Amazon ElastiCache in an Amazon VPC

like image 160
greg_diesel Avatar answered Sep 22 '22 14:09

greg_diesel


Setting up an HTTP Proxy or iptables wouldn't work for the following reasons:

Redis calls are not HTTP and will not be handled by HTTP proxies. iptables (or any port forwarding for that matter) will either won't accept a domain name as destination or is highly inefficient due to DNS resolution required every time.

The best and convenient method is to install twemproxy in an EC2 machine and route your requests through it. As a bonus, you suddenly have deployed a fantastic sharding strategy as well.

like image 31
Nirmal Avatar answered Sep 21 '22 14:09

Nirmal