localstack / serverless-localstack

⚡ Serverless plugin for running against LocalStack
511 stars 82 forks source link

Connection refused trying to access to an external container #191

Closed Warkanlock closed 8 months ago

Warkanlock commented 2 years ago

Hi! I'm trying to connect in between two containers (one database on a network called development) and the other using serverless-localstack with the following configuration:

  localstack:
    debug: true
    host: "http://  localhost"
    autostart: true
    stages:
      - local
    networks:
      - development

Everything looks OK until I want to access to the database using a HTTP connector inside the Lambda: I receive a Connection refused for 127.0.0.1:5732 which makes sense, since I'm trying to access to a different container, but I'm configuring the development network and happens.

Does anyone knows how to connect a local lambda to a database running in other container? This issue is driving me crazy

gfpacheco commented 1 year ago

@Warkanlock I had the same issue, and it took me two days to fix it.

The lambda functions don't actually run on the same container as the localstack. A new container is created for each lambda, and that container is not added to the networks you configured.

To actually get your lambdas in a network you need to have the LAMBDA_DOCKER_NETWORK env var set before you start the localstack.

LAMBDA_DOCKER_NETWORK=development serverless deploy

Or add it to the .env file and add useDotenv: true to the root of serverless.yml

steffyP commented 8 months ago

Hi @Warkanlock, it seems like a solution to your problem has been provided, so we are closing the ticket. Please let us know if you still encounter any issues.