0
votes

I've set up localstack running on docker. I have a .Net Core 2.1 c# Lambda function that is trying to connect to a MySql database on localhost. This is what I get in the console:

"Unable to connect to any of the specified MySQL hosts"

This is what my connection string looks like:

"Data Source=localhost;Initial Catalog=xxx;Host=localhost;Connection Timeout=10;User ID=xxxx;Password=xxxx;SSL Mode=none"

I've tried various IP addresses (127... etc) including our live DB connection string.

EDIT (23-Apr-2019): Command I run on the localstack folder:

docker-compose up

Here's the docker file I'm using:

version: '2.1'

services:   localstack:
    image: localstack/localstack
    ports:
      - "4567-4593:4567-4593"
      - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
    environment:
      - SERVICES=lambda,sqs,dynamodb,s3
      - DEBUG=1
      - DATA_DIR=/tmp/localstack/data
      - PORT_WEB_UI=${PORT_WEB_UI- }
      - LAMBDA_EXECUTOR=docker-reuse
      - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
1
Can you provide the dockerfile and docker run command you are using? - Mihai
Thanks, @Mihai - I have added what I think you need (sorry for delay - was Easter weekend here!) - andrew_tap
Can you run "docker-compose config" and make sure all the environment variables are set correctly? Also can you run "docker-compose ps" and post the result? In the meantime I am trying to run this on my own as well. - Mihai
@Mihai - thanks for your time, I've actually solved this and turns out I was just being a cotton-headed ninny-muggins... I have localhost in my MySql conn string. I needed to update that to the Ethernet adapter's IP. It works now so I'll post that as an answer. - andrew_tap

1 Answers

0
votes

So I solved this myself and I was just being silly after all...

I had to update the "host" of my MySql connection string from "localhost" to the IP address of my Ethernet Adapter IP as follows:

"Data Source=172.x.x.x;Initial Catalog=xxx;Host=localhost;Connection Timeout=10;User ID=xxxx;Password=xxxx;SSL Mode=none"