[英]how to connect a lambda function (behind an api gateway) to a private rds in a vpc
我有以下 AWS VPC 配置:
load balancer
前面。 load balancer
鏈接到public subnets
,而我的RDS 數據庫位於private subnets
中。我想要完成的是:
API Gateway
is connected to a lambda function
that, when called/triggered, the function must update some table data of my (private) RDS Postgres instance.據我了解,第一步是為 lambda function 創建一個 IAM 角色,以便只能由上述 IP 地址訪問。
現在,從連接到 API 網關的 lambda 訪問私有 RDS 的最佳方法是什么? 尤其是不使用 Nat Gateway,因為與之相關的瘋狂成本。
有人可以幫我弄清楚怎么做嗎,我指的是高級別的理解怎么做?
As Norman said in their comment, you can control access to your API in API Gateway, and limit it to certain IP addresses, with API Gateway Resource Policies . 這將同時控制對 API 后面的 Lambda 的訪問。
然后,您可以編輯 Lambdas Configuration -> VPC
設置並將其添加到可以訪問您的 RDS 數據庫的子網中(並將其放置在與數據庫相同的子網中,或者將其放置在對 RDS 子網具有訪問權限的另一個子網中)。 要將 Lambda 連接到 VPC,Lambda 執行角色需要以下權限
ec2:CreateNetworkInterface
ec2:DescribeNetworkInterfaces
ec2:DeleteNetworkInterface
例如,它們包含在托管策略AWSLambdaVPCAccessExecutionRole
中。 您可以在此處閱讀有關配置 Lambda 以進行 VPC 訪問的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.