Lambda function web scraping with requests.get() is timing out? or getting blocked

0

I have a lambda function that uses requests.get() to run sentiment analysis on websites, and the function is run through an API call. I recently updated the function though, so that now it's linked to an EFS (where dependencies are stored), and also a VPC due to security. However, now when I test my web extension which will run the lambda function, my lambda function is unable to retrieve text from the website, aka it's failing on the requests.get() line.

I did a bit of research, and I'm thinking that this may be because of the newly connected VPC, which is causing the lambda function to run on subnets that are commonly blocked by most websites. If this is the case, does anyone know a workaround?

hczhang
已提问 10 个月前480 查看次数
2 回答
1
已接受的回答

Hi,

I recommend that you take a look at the following Knowledge Center article which describes how to grant internet access to an AWS Lambda function that's connected to a VPC, since it may be that the VPC or subnet are not correctly configured and you do not have access to that public website.

profile picture
专家
已回答 10 个月前
  • Hi, thanks for the advice. I created a new VPC with internet access and I'm now able to run requests.get(). However, I made a new EFS as well using the new VPC but now I'm unable to attach it to my lambda function. When I try to test my function, I get the following error: Calling the invoke API action failed with this message: The function couldn't connect to the Amazon EFS file system

  • This error is usually related with the security group and routing configuration for the VPC subnets. Can you check that it is correctly configured as described in the attached documentation?

  • Turns out I just didn't change the network VPC of the EFS to the new VPC I created. Doing so allowed me to mount it successfully to the Lambda function. Thanks!

0

When you connect your function to a VPC, you loose internet access. To access the internet, you will need to deploy a NAT Gateway into the VPC. Note that this will add cost.

To overcome this cost, consider moving the configuration to S3, and run the function not attached to the VPC.

profile pictureAWS
专家
Uri
已回答 10 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则