0

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 2

2

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).

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

5 Comments

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.
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?
Good to know I'll check it and get back to you.
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!
Did you verify the security group assigned to the Memcached instance had the correct port open?
0

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".

Comments

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.