aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Bug: Cant Connect to a database behind a SSL tunnel in my machine using `sam local start-api`

Open octaviosanti351 opened this issue 7 months ago • 2 comments

Description

I'm trying to connect to a external database that is outside an SSL tunnel with a .pem file. The tunnel is in my local machine in the port (for example 27001) . The docker container cant acces to the port of my machine. I tried to set the container in the host network using host.docker.internal but it doesnt work... I'm using Manjaro Linux.

Steps to reproduce

I tried to:

  • Create a custom dockerfile with the port binding
  • Bind the host network to the sam local start-api command and use host.docker.internal

Im Using:

Os: Manjaro linux sam version: 1.127.0

None of these works

octaviosanti351 avatar May 03 '25 22:05 octaviosanti351

Hi. I found some other similar reports to this in the past, and it could be that the --docker-network parameter (that should allow this behavior) doesn't work correctly.

#7732 #3609

What does work as a workaround, is to add a host to your container, making localhost inside of it to refer to your actual localhost where your tunnel is running.

sam local start-api --add-host localhost:host-gateway

With this, you can call localhost:27001 from inside your Lambda function and it will call the host-gateway, which refers to your laptop or environment where you're running the sam command. You can also change localhost in that command and choose whatever name you want, and then inside your function's code, you can make a call to a port using that name.

valerena avatar May 28 '25 02:05 valerena

Cool! I will try it. Thank you!

octaviosanti351 avatar Jun 13 '25 18:06 octaviosanti351