简体   繁体   English

无法通过AWS Lambda函数连接到在AWS EC2上运行的MySQL实例

[英]Unable to connect to MySQL instance running on AWS EC2 from AWS Lambda function

I am writing an AWS Lambda function to connect to a MySQL instance running on EC2. 我正在编写一个AWS Lambda函数以连接到在EC2上运行的MySQL实例。 I have associated the Lambda function with the same subnet and security group that the EC2 is configured in. I checked the Lambda function's IAM roles and that has AWSLambdaVPCAccessExecutionRole policy attached to it. 我已将Lambda函数与配置EC2的子网和安全组关联。我检查了Lambda函数的IAM角色,并AWSLambdaVPCAccessExecutionRole附加了AWSLambdaVPCAccessExecutionRole策略。 However I am still not able to connect to the MySQL instance. 但是,我仍然无法连接到MySQL实例。

I tried allowing traffic from anywhere and that worked but now I am not sure how to connect to the MySQL instance with stricter security rules. 我试着允许来自任何地方的流量,但仍然有效,但现在我不确定如何使用更严格的安全规则连接到MySQL实例。

I am using Kotlin to write my lambda function and using serverless to deploy changes to lambda. 我正在使用Kotlin编写我的lambda函数,并使用lessserver将更改部署到lambda。

I have tried every possible solution available online to make this happen but I haven't had any positive results yet. 我已经尝试了所有可能的在线解决方案来实现这一目标,但是我还没有得到任何积极的结果。

You have associated the Lambda function with the same security group. 您已将Lambda函数与同一安全组关联。 But just that would not do. 但是,那是行不通的。 You also need to add an ingress rule to allow traffic to the security group from itself. 您还需要添加一个入口规则,以允许流量从自身流向安全组。 Basically, you need to self reference the security group. 基本上,您需要自引用安全组。

Add a rule to allow traffic on the mysql port from sg-xxxxxxxx. 添加一条规则,以允许sg-xxxxxxxx在mysql端口上进行通信。

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

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