When I was on my internship period, I tried to create serverless application to monitor Datadog API Key and its usages using SAM. As I explored into template application that run dynamoDB and lambda function at local, I found some problem at that template.
python person_table = boto.client(..., endpoint='http://localhost:8000/')
(note this application written using python 3.8)
Before we got deeper into problem, I ran dynamoDB at port
8000
and SAM API at port 3000
. The problem
comes when the code above cannot find any services on port
8000
.
So, I thought it is quite weird because I was sure that I set up the
port correctly. The fact that I can open dynamoDB shell
(http://localhost:8000/shell
) on browser should be
sufficient proof.
As I search and found this
article. I thought that It would solve the problems. Turns out It
didn’t and host.docker.internal
only exist on WSL.
So after I searched at stackoverflow , I found that
localhost
, in this case means local on container created by
SAM. Well, the solution is to change to 172.17.0.1 that is the default
subnet for docker container to communicate each other.