简体   繁体   English

VPC 之外的 AWS Elasticache/Redis 访问?

[英]AWS Elasticache/Redis Access Outside of VPC?

I have a lambda I want to run outside of my VPC to avoid NAT costs.我有一个 lambda 我想在我的 VPC 之外运行以避免 NAT 成本。 The only service it needs to access within the VPC is an Elasticache instance.它需要在 VPC 中访问的唯一服务是 Elasticache 实例。 I can't create a VPC Endpoint between my lambda and Elasticache, so I'm not sure how I can connect to it without putting my lambda within the VPC and going through NAT.我无法在我的 lambda 和 Elasticache 之间创建 VPC 端点,所以我不确定如果不将我的 lambda 放在 VPC 中并通过 NAT,我该如何连接到它。

How can I connect to a redis instance outside of the VPC?如何连接VPC外的redis实例? Bastion server?堡垒服务器?

I think in your cases there are 3 possible solutions:我认为在您的情况下,有 3 种可能的解决方案:

  1. Like one of the folks said above, deploy our own NAT instance on EC2 instead of using AWS NAT Gateway which can be quite expensive.就像上面的一个人所说的那样,在 EC2 上部署我们自己的 NAT 实例,而不是使用可能非常昂贵的 AWS NAT 网关。 But of coz you will need to setup / maintain and scale the NAT instance yourself.但是因为您需要自己设置/维护和扩展 NAT 实例。
  2. Deploy a proxy in EC2 in public subnet of the VPC, said deploy a Nginx and set proxy_pass to the ElastiCache cluster in the VPC.在VPC公有子网的EC2中部署一个proxy,即部署一个Nginx并将proxy_pass设置为VPC中的ElastiCache集群。 In this way your lambda outside VPC can call the Nginx Elastic IP for ElastiCache requests.通过这种方式,您在 VPC 外的 lambda 可以为 ElastiCache 请求调用 Nginx 弹性 IP。 But please consider to put Network LB in front of an auto scaling group of Nginx EC2 for resiliency.但是请考虑将 Network LB 置于 Nginx EC2 的自动缩放组之前以实现弹性。 Main concern in this solution is security, your nginx security group need to open 0.0.0.0/0 for EC access (as lambda outside VPC come with different public IPs and no security group itself), ensure you enable encryption in transit and access control using AUTH or RBAC in Redis (if your EC is redis for example)此解决方案的主要问题是安全性,您的 nginx 安全组需要打开 0.0.0.0/0 以进行 EC 访问(因为 VPC 外的 lambda 具有不同的公共 IP,并且本身没有安全组),请确保您启用传输中的加密和访问控制使用Redis 中的 AUTH 或 RBAC(例如,如果您的 EC 是 redis)
  3. Both 1 and 2 involve building a EC2 instance yourself which increase maintenance burden. 1 和 2 都涉及自己构建 EC2 实例,这会增加维护负担。 I think the best solution is to breakdown your Lambda function into two functions, one handle the EC call (Lambda A) and the other handle the internet API call (Lambda B), put Lambda A in VPC while keep Lambda B outside VPC, and simply use invoke API to call Lambda B from A or vice versa.我认为最好的解决方案是将您的 Lambda 函数分解为两个函数,一个处理 EC 调用(Lambda A),另一个处理 Internet API 调用(Lambda B),将 Lambda A 放在 VPC 中,同时将 Lambda B 保留在 VPC 之外,以及只需使用调用 API 从 A 调用 Lambda B,反之亦然。 This should be the best solution but involves more work in coding perspective.这应该是最好的解决方案,但在编码方面涉及更多工作。

Problem with two lambda functions is the extra delay when invoking another lambda function just for making a cache request.两个 lambda 函数的问题是调用另一个 lambda function 只是为了发出缓存请求时的额外延迟。 Because lambda invoke takes at least an extra 10-20ms, which is much longer than what redis request would take.因为 lambda 调用至少需要额外的 10-20 毫秒,这比 redis 请求花费的时间要长得多。

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

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