简体   繁体   English

将python AWS Lambda函数连接到ElastiCache

[英]Connecting a python AWS Lambda function to ElastiCache

I'm trying to set and get keys from ElastiCache (memcached) from a python lambda function using Boto3. 我正在尝试使用Boto3从python lambda函数设置并从ElastiCache(memcached)获取密钥。 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? 是否有一些文档可以显示整个过程?

It sounds like you are trying to interact with Memcached via Boto3. 听起来您正在尝试通过Boto3与Memcached进行交互。 This is not possible. 这是不可能的。 Boto3 is for interacting with the AWS API. Boto3用于与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. 您可以通过AWS API管理ElastiCache服务器,但不能与在这些服务器上运行的Memcached软件进行交互。 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. 您需要在Python代码中使用像python-memcached这样的Memcached客户端库来实际获取和设置Memcached集群中的密钥。

Also, your Lambda function will need to reside in the same VPC as the ElastiCache node(s). 此外,您的Lambda函数将需要与ElastiCache节点驻留在同一VPC中。

I had the exact timeout problem listed in the commment of the older post. 我在旧帖子的留言中列出了确切的超时问题。 My bug is in the security group for memcached. 我的错误在memcached的安全组中。 Here is the working version in terraform: 这是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". 我通过在公共子网中创建EC2实例来测试连接,然后执行“ telnet(输入缓存节点URL)11211”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM