-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send GET request to "sam local start-api" from a Python Function "sam local invoke X" #4101
Comments
@gccalvin When you provide |
Hello @jfuss I removed the docker network, which means start-api runs on localhost and sam local invoke runs on a docker container? I still couldn't connect with localhost, 127.0.0.1, host.docker.internal: I found this. Which mentioned 172.17.0.1 being used for the default network bridge. This time I got the following error: I also tried the following with no luck: (using host.docker.internal in the function) My function can send GET requests to other servers, like google.com, and a curl on the vm to 127.0.0.1 has no issues. Are there any extra networking arguments I should be passing to my sam commands to get the function to communicate with the Ubuntu vm? Or do you know of a working case where a sam local invoke could send requests to the sam local start-api? I can provide more info if needed. Thank you. |
@gccalvin In my experience with Docker, the networking for it is super confusing.
I would be cautious. Unless Docker has that specifically documented, it can change and by one of the comments it depends on how you have things setup. "This DOES NOT work on all cases. If you have other networks, a new interface is going to be created: 172.17.0.1, 172.18.0.1, 172.19.0.1 and so on (try ifconfig to list all interfaces). You have to manually obtain the IP for your network"
To be precise,
This is not surprising and has to do how the containers do DNS (more or less). So a lookup for google can resolve but a lookup to you machines localhost will not (from the container) without the IPAddress to route the request. On the VM to 127.0.0.1, that also makes sense since the VM would be able to do the lookup for where your localhost is on that machine. #510 (comment) might help? Maybe what you are missing is |
Hello @jfuss Thank you for the information, and linking that issue. However, in their case, they are using However, I've come to the conclusion that there is no need for a SAM function to locally test my main lambda function, when I can just call it as a regular python function. I removed my I'm still not completely sure why the function launched in a docker from Thanks for your help! |
Hello. This is most likely a misunderstanding on my part.
I am using a Github Action workflow running ubuntu-latest, with python 3.9, with aws-actions/setup-sam@v2.
After running sam build and validate, I run the following:
My function (VisitorCounterIT) looks like:
I know lambda needs to return JSON, but the issue is that it can't reach the local-api:
However, I can curl the api with no issues through the vm. Also, I've commented out the local docker DynamoDB database for debugging, but I was able to connect from the function to the DynamoDB through the endpoint_url='http://dynamodb:8000'
Is there an endpoint url I should be using to send this GET request?
I've tried messing with some of the container parameters and not using the docker network, but I still can't get pass this. I also tried the host.docker.internal, localhost, and local docker IP, and the I get the same error. --container-host-interface 0.0.0.0 also doesn't help.
Any help would be appreciated, thank you.
The text was updated successfully, but these errors were encountered: