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?

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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠