0
votes

I have a lambda application that needs to access Elasticache with Memcached engine.

I have configured my elasticache correctly, and can even access it from Elastic beanstalk. I have connected to my node via telnet for testing as well.

To access elasticache from Lambda, I have done the following:

  1. Configured my cache, and confirmed connecting, setting and getting cached items from my node
  2. Setup my function to run off of the same VPC as my cluster
  3. Assigned my function the subnet used by my cache (Subnet group), and resides in the same VPC.
  4. Assigned my function the Security group that opens port 11211
  5. My function Role has the following policies attached (AWSLambdaFUllAccess, AWSLambdaBasicExecutionRole and AWSLambdaVPCAccessExecutionRole).

Is there something else I need to be doing?

I get the following in the logs

Error Enyim.Caching.MemcachedClient: Create PooledSocket
    Error Enyim.Caching.MemcachedClient: Could not init pool.
    Debug Enyim.Caching.MemcachedClient: Mark as dead was requested for 
Unspecified/mynodeurl.cache.amazonaws.com:11211
Debug Enyim.Caching.MemcachedClient: FailurePolicy.ShouldFail(): True
 Warning Enyim.Caching.MemcachedClient: Marking node 
Unspecified/mynodeurl.cache.amazonaws.com:11211 as dead
 Debug Enyim.Caching.MemcachedClient: Node 
Unspecified/mynodeurl.cache.amazonaws.com:11211 is dead.
 Debug Enyim.Caching.MemcachedClient: Starting the recovery timer.
 Debug Enyim.Caching.MemcachedClient: Timer started.
 Information Enyim.Caching.MemcachedClient: MemcachedInitPool-cost: 43.048ms
 Debug Enyim.Caching.MemcachedClient: Acquiring stream from pool. 
 Unspecified/mynodeurl.cache.amazonaws.com:11211
 Debug Enyim.Caching.MemcachedClient: Pool is dead or disposed, returning null 
 Unspecified/mynodeurl.cache.amazonaws.com:11211
 EnyimMemcached Started.

Thanks

1
Your comment about your security group is unclear. It sort of sounds like you opened port 11211 on the Lambda function's security group, which would be wrong. Did you create a rule in the security group assigned to the ElastiCache cluster such that the Lambda function would have access? - Mark B
Thanks for the response @MarkB. You are correct. I am using the same Security Group as my Elasticache node for my lambda function. What settings should my Lambda Security group have? It currently only has inbound rules for port 11211 and Outbound - All - Akin
You should probably add some sample code you used, maybe there's something in client config that is missing. - Adam Owczarczyk
Hi Adam. The code is fine. I'm pretty sure it is a configuration issue. I think the question I need to answer is from @MarkB, Did you create a rule in the security group assigned to the ElastiCache cluster such that the Lambda function would have access?. I'm not sure what rule that would be. Any input will help on how to configure the elasticache security group to allow lambda will be helpful - Akin
Please post your exact security group settings. What is the source value for the port 11211 rule? - Mark B

1 Answers

0
votes

Sounds like you are using the wrong version of Enyim.Caching.MemcachedClient. At time of writing Lambda only supports .netstandard 1.6 not 1.6.1.

Enyim has a very early version of their client that will work. https://www.nuget.org/packages/EnyimMemcachedCore/1.0.0.6

If you enable full logging you'll see that the exception that comes along with "Could not init pool" is "Operation is not supported on this platform."

I had this exact same problem.