I'm trying to set and get keys from ElastiCache (memcached) from a python lambda function using Boto3. I can figure out how to get the endpoints but that's pretty much it. Is there some documentation out there that shows the entire process?
2 Answers
It sounds like you are trying to interact with Memcached via Boto3. This is not possible. Boto3 is for interacting with the AWS API. You can manage your ElastiCache servers via the AWS API, but you can't interact with the Memcached software running on those servers. You need to use a Memcached client library like python-memcached in your Python code to actually get and set keys in your Memcached cluster.
Also, your Lambda function will need to reside in the same VPC as the ElastiCache node(s).

- 183,023
- 24
- 297
- 295
-
Thanks. I use pymemcache to interact with memcache. I retrieve the endpoint using Boto, connect to elasticache with pymemcache without a problem but when I do a set command it blocks until my lambda function times out. I can connect, but I can't set. I'm missing a step here. – Martin Giroux Nov 05 '17 at 12:58
-
Are you sure it's verifying the connection? I'm not sure about memcached, but I know with Redis it doesn't actually establish a connection until you try to do something. If memcached is similar then you may not be actually connecting at all. What are the VPC settings of your Lambda function? – Mark B Nov 05 '17 at 13:05
-
Good to know I'll check it and get back to you. – Martin Giroux Nov 05 '17 at 13:10
-
The problem is with memcache. Redis works fine. If I wasn't so busy I would try to figure it out but Redis is working so I'm going to use that. Thanks for your help @Mark B. I may need your help for other things, AWS is quite a beast! – Martin Giroux Nov 06 '17 at 14:06
-
Did you verify the security group assigned to the Memcached instance had the correct port open? – Mark B Nov 06 '17 at 14:15
I had the exact timeout problem listed in the commment of the older post. My bug is in the security group for memcached. Here is the working version in terraform:
resource "aws_security_group" "memcached" {
vpc_id = "${aws_vpc.dev.id}"
name = "memcached SG"
ingress {
from_port = "${var.memcached_port}"
to_port = "${var.memcached_port}"
protocol = "tcp"
cidr_blocks = ["${var.public_subnet_cidr}"]
}
egress {
from_port = "${var.memcached_port}"
to_port = "${var.memcached_port}"
protocol = "tcp"
cidr_blocks = ["${var.public_subnet_cidr}"]
}
tags = {
Name = "memcached SG"
}
}
I tested the connection by creating a EC2 instance in public subnet and do "telnet (input your cache node URL) 11211".

- 23
- 7