As mentioned in the help for sam local invoke, you can connect your Docker container to an existing Docker network:
▶ sam local invoke --help
...
--docker-network TEXT Specifies the name or id of an existing
docker network to lambda docker containers
should connect to, along with the default
bridge network. If not specified, the Lambda
containers will only connect to the default
bridge docker network.
So, to list your Docker networks:
▶ docker network ls
NETWORK ID NAME DRIVER SCOPE
25a03c8453a6 bridge bridge local
00de89cf09d0 host host local
41597d91a389 none null local
Then, to connect your Lambda function's Docker container to the host network:
▶ sam local invoke "lambda function name" --event event.json \
--docker-network 00de89cf09d0
Note that you can also use the environment variable SAM_DOCKER_NETWORK
:
▶ SAM_DOCKER_NETWORK=00de89cf09d0 sam local invoke "lambda function name" \
--event event.json
As mentioned here.
Assuming the host network can access the RDS instance, that should fix your problem.