Access AWS S3 from Lambda within Default VPC

你。 提交于 2021-02-10 15:43:16

问题


I have a lambda function which needs to access ec2 through ssh and load files and save it to s3. So,for that I have kept ec2 and lambda both in default VPCs and same subnet. Now the problem is that I am able to connect the function to ec2 but not to s3.

Its killing me since morning as when I remove the vpc settings it uploads the files to s3 ,but then connection to ec2 is lost.

I tried to add a NAT gateway to default VPC(although I am not sure I did it correctly or not because I am new to this) but it didnt do anything.

I am confused as my ec2 instance which s in the same VPC and subnet can access internet but lambda function is not able to access s3.

I am not sure how to proceed.

Please help!!!


回答1:


The Lambda function will not get a public IP assigned to it from within a VPC, so it will never have direct Internet access like your EC2 instance has. You will have to move the Lambda function to a private subnet with a route to a NAT Gateway in order to give it Internet access. It sounds like you attempted this but configured it incorrectly.

If all the Lambda function needs to access is S3, then it is easier to setup a VPC Endpoint (AWS PrivateLink) in your VPC.



来源:https://stackoverflow.com/questions/54112422/access-aws-s3-from-lambda-within-default-vpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!