Skip to content

Plugin not working with Serverless v4 inside containerized environment #279

@TeemuLeino

Description

@TeemuLeino

When using the serverless-localstack plugin with Serverless Framework v4 inside a Docker container, the plugin fails to properly redirect all AWS SDK calls to the LocalStack container. Despite configuring the correct endpoint URL, some AWS SDK calls still attempt to connect to localhost:4566 instead of the LocalStack container, resulting in connection refused errors.

Environment Details

  • Serverless Framework Version: 4.18.2
  • serverless-localstack Version: 1.3.1
  • Node.js Version: 22.16.0
  • Docker Environment: Docker Compose with separate containers for LocalStack and Serverless deployment

Configuration

docker-compose.yml:

services: aws: image: localstack/localstack-pro container_name: localstack environment: - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} ports: - '4566:4566' - '4510-4559:4510-4559' volumes: - /var/run/docker.sock:/var/run/docker.sock test: build: context: . dockerfile: Dockerfile environment: - SERVERLESS_LICENSE_KEY=${SERVERLESS_LICENSE_KEY} - AWS_ACCESS_KEY_ID=dummy - AWS_SECRET_ACCESS_KEY=dummy - AWS_ENDPOINT_URL=http://aws:4566 command: npm run deploy:local depends_on: aws: condition: service_healthy 

serverless.yml:

service: my-test-project plugins: - serverless-localstack custom: localstack: stages: - local provider: name: aws runtime: nodejs22.x region: eu-central-1 stage: local functions: hello: handler: build/index.hello events: - httpApi: path: / method: get 

Expected Behavior

All AWS SDK calls should be redirected to http://aws:4566 (the LocalStack container) when running inside the Docker environment.

Actual Behavior

The deployment fails with connection errors as some AWS SDK calls still attempt to connect to 127.0.0.1:4566 (localhost) instead of the LocalStack container:

✖ Error: connect ECONNREFUSED 127.0.0.1:4566 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1637:16) 

Terminal Output

From the logs, I can see that:

  1. LocalStack starts successfully and is ready
  2. The serverless-localstack plugin reports "Reconfigured endpoints"
  3. Some AWS calls succeed (e.g., AWS sts.GetCallerIdentity => 200)
  4. But the deployment ultimately fails with connection refused to localhost

Workaround

The issue does not occur when:

  • Running Serverless Framework v4 directly on the host machine (outside Docker)
  • Using LocalStack running on the host machine
  • The same configuration works perfectly in non-Docker environments

Reproduction Steps

  1. Clone the repository: https://github.com/TeemuLeino/localstack-sls-v4
  2. Set up environment variables:
 export LOCALSTACK_AUTH_TOKEN=your_token export SERVERLESS_LICENSE_KEY=your_license 
  1. Run: docker compose up --build
  2. Observe the connection refused error

Additional Information

  • The issue appears to be related to how the serverless-localstack plugin handles endpoint configuration in containerized environments
  • The plugin seems to partially reconfigure endpoints but not all AWS SDK calls are properly redirected
  • This is specifically a problem with Serverless Framework v4 in Docker environments
  • The same setup works fine with Serverless Framework v3

Files

This issue prevents the use of serverless-localstack in containerized CI/CD pipelines and development environments where both LocalStack and Serverless Framework need to run in separate containers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions