执行AWS Lambda函数时如何选择Elastic IP [英] How to choose Elastic IP when my aws lambda function execute
问题描述
当我执行lambda函数时,我想选择自己的特定Elastic IP.
I want to select specific Elastic IP my own when my lambda function executed.
我的服务必须根据用户的属性来响应多种情况. 我可以在可以选择特定我自己的弹性IP的lambda函数中编写代码吗?
my service has to respond to several situations, and by user's attributes. Could I write code in a lambda function, that can choose specific my own elastic IP?
我已经搜索过了.但是旧的信息说它做不到. 但是最近我听说可以通过使用网络负载平衡器或应用程序负载平衡器来实现. 但是我不知道该怎么用.
I had searched for this. but old information says it cannot do. but recently I heard about it is possible by using Network Load Balancer or Application Load Balancer. But I don't know how to use this for the problem.
推荐答案
否.您不能将弹性IP(EIP)地址与AWS Lambda函数关联.
No. You cannot associate an Elastic IP (EIP) address with an AWS Lambda function.
嗯,实际上可以,但是我不建议这样做.当Lambda函数与VPC关联时,它通过弹性网络接口(ENI)连接.可以将EIP附加到ENI.如果它连接到公共子网,这还将授予对Internet的访问权限.
Well, actually you can, but I wouldn't recommend it. When a Lambda function is associated with a VPC, it connects via an Elastic Network Interface (ENI). It is possible to attach an EIP to an ENI. This also grants access to the Internet if it is attached to a public subnet.
那为什么要避免呢?因为Lambda可能会创建其他ENI,尤其是在Lambda函数经常被调用并并行运行的情况下.这意味着它将没有一致的ENI.
So why avoid it? Because Lambda might create additional ENIs, especially if the Lambda function is frequently invoked and run in parallel. This means it will not have a consistent ENI.
另一种方法是:
- 将AWS Lambda函数附加到私有子网
- 在公共子网中放置 NAT网关
- 将弹性IP地址与NAT网关相关联
- 从Lambda函数到Internet的所有流量都将来自NAT网关的EIP(但是,我认为您无法更改该EIP)
- Attach the AWS Lambda function to a private subnet
- Put a NAT Gateway in a public subnet
- Associate an Elastic IP address with the NAT Gateway
- All traffic from the Lambda function to the Internet will then come from the NAT Gateway's EIP (however, I don't think you can change that EIP)
这篇关于执行AWS Lambda函数时如何选择Elastic IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!