I have a python lambda function that is using requests to scrape metrics from Prometheus, which is http. I began by zipping the requests packages and a python function on my local machine. I uploaded and attached the zip file as a layer to the lambda function. When I test the function it times out on the GET request
import requests
import copy
import json
print("Imported packages successfull" )
# Grabbing metadata on metrics categoriies
print("Reading URL")
URL_meta = 'http://xxx.xxx.x.xxx:9091/api/v1/metadata'
print("URL read successfull")
print("Initiating requests.get")
r = requests.get(url = URL_meta) <--------- Times out
print("successful requests.get")
metadata = r.json()
I then made a VPC 10.0.0.0/16, a Public and Private Subnet which I attached to their respective Public and Private Route tables, an Internet Gateway attached to the VPC, a Public NAT Gateway connected to the Public Subnet, I made a Role and attached the permission policies: AWSLambdaExecute and AWSLambdaVPCAccessExecutionRole. I then went to the Lambda Function > Configuration > VPC, and added the VPC I made, attached the Private Subnet and the default VPC Security group to that. I then went to Lambda Function > Configuration > Permissions, and assigned the Execution Role.
When I run the function it times out at the same location. Here are the logs:
Function Logs
START RequestId: aa1e5ffa-ed04-4274-9a66-a5ac455b5325 Version: $LATEST
Imported packages successfull
Reading URL
URL read successfull
Initiating requests.get
END RequestId: xxxxxxxxx
I have successfully run the same requests function from a Jupyter Notebook on my local machine and have verified that the http address can be accessed from various devices.
I have increased the timeout period to 30 seconds. I have searched google, I have checked SO:
Cannot use Requests-Module on AWS Lambda
Issue with VPC attached to Lambda function
Why is my Lambda unable to access the internet?
How to make a HTTP rest call in AWS lambda using python?
Python request in AWS Lambda timing out
get request Task timed out in Lambda using Python
I've watched numerous YouTube videos, poured over the AWS Docs, read Medium articles, and I checked the "Similar Questions" that were suggested when I initiated this. I am stuck.