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 Antworten
1
Akzeptierte Antwort

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
EXPERTE
beantwortet vor 10 Monaten
  • 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
EXPERTE
Uri
beantwortet vor 10 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen