Access AWS S3 from Lambda within VPC

前端 未结 6 1719
旧巷少年郎
旧巷少年郎 2020-12-08 06:57

Overall, I\'m pretty confused by using AWS Lambda within a VPC. The problem is Lambda is timing out while trying to access an S3 bucket. The solution seems to be a VPC Endpo

6条回答
  •  被撕碎了的回忆
    2020-12-08 07:09

    There's another issue having to do with subnets and routes that is not addressed in the other answers, so I am creating a separate answer with the proviso that all the above answers apply. You have to get them all right for the lambda function to access S3.

    When you create a new AWS account which I did last fall, there is no route table automatically associated with your default VPC (see Route Tables -> Subnet Associations in the Console).

    So if you follow the instructions to create an Endpoint and create a route for that Endpoint, no route gets added, because there's no subnet to put it on. And as usual with AWS you don't get an error message...

    What you should do is create a subnet for your lambda function, associate that subnet with the route table and the lambda function, and then rerun the Endpoint instructions and you will, if successful, find a route table that has three entries like this:

    Destination     Target
    10.0.0.0/16     Local
    0.0.0.0/0       igw-1a2b3c4d
    pl-1a2b3c4d     vpce-11bb22cc
    

    If you only have two entries (no 'pl-xxxxx' entry), then you have not yet succeeded.

    In the end I guess it should be no surprise that a lambda function needs a subnet to live on, like any other entity in a network. And it's probably advisable that it not live on the same subnet as your EC2 instances because lambda might need different routes or security permissions. Note that the GUI in lambda really wants you to have two subnets in two different AZs which is also a good idea.

提交回复
热议问题