Skip to content

bug: connection to ApiGatewayv2 WebSocket always receive close message #13198

@duesabati

Description

@duesabati

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Once created an apigatewayv2 with WebSocket protocol, using whatever websocket client to connect to it, attempting to connect to is impossible due to the following error printed by the locastack-pro container:

aws-1  | 2025-09-26T08:01:43.071  INFO --- [-functhread5] websockets.server          : connection open
aws-1  | 2025-09-26T08:01:43.077  INFO --- [functhread14] localstack.utils.threads   : Thread run method <function AdaptiveThreadPool.submit.<locals>._run at 0x7f0df42668e0>(None) failed: 'ApiGatewayManagementApiBackend' object has no attribute 'apis' Traceback (most recent call last):
aws-1  |   File "/opt/code/localstack/.venv/lib/python3.11/site-packages/localstack/utils/threads.py", line 60, in run
aws-1  |     result = self.func(self.params, **kwargs)
aws-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
aws-1  |   File "/opt/code/localstack/.venv/lib/python3.11/site-packages/localstack/utils/asyncio.py", line 51, in _run
aws-1  |     return fn(*args, **kwargs)
aws-1  |            ^^^^^^^^^^^^^^^^^^^
aws-1  |   File "/opt/code/localstack/.venv/lib/python3.11/site-packages/localstack/pro/core/services/apigatewayv2/next_gen/execute_api/websockets_legacy/websocket_async_handler.py.enc", line 42, in A
aws-1  |     if not d:LOG.debug('Authorization denied when accessing WebSocket API "%s": %s',L,W.content);raise DeniedAuthorization(W.content)
aws-1  |                                                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
aws-1  | localstack.pro.core.services.apigateway.legacy.authorizers.DeniedAuthorization: 'ApiGatewayManagementApiBackend' object has no attribute 'apis'
aws-1  | 
aws-1  | 2025-09-26T08:01:45.927  INFO --- [-functhread5] websockets.server          : connection closed

I don't know if it can be related but whenever I go to the page of apigateway of the localstack console it logs the following error

aws-1  | 2025-09-26T08:01:31.643  INFO --- [et.reactor-1] localstack.request.aws     : AWS apigateway.GetRestApis => 501 (InternalFailure)
aws-1  | 2025-09-26T08:01:31.928  INFO --- [et.reactor-0] localstack.aws.skeleton    : No moto route for service apigateway on path /restapis found.

Expected Behavior

It should connect to the websocket client.

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

How are you starting localstack

services:
  aws:
    image: localstack/localstack-pro:4.8.1
    ports:
      - "4566:4566" # LocalStack Gateway
      - "4510:4510"
    environment:
      - DEBUG=${DEBUG:-0}
      - AWS_DEFAULT_REGION=us-east-1
      - AWS_REGION=us-east-1
      - AWS_ACCESS_KEY_ID=test
      - AWS_SECRET_ACCESS_KEY=test
      - LOCALSTACK_AUTH_TOKEN=***
      - PERSISTENCE=1
    volumes:
      - "${HOST_WORKSPACE_DIR}:/home/localstack"
      - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"


networks:
  default:
    external: true
    name: ${WORKSPACE_NETWORK_NAME}
docker compose up

Client commands

awslocal apigatewayv2 create-api
--name "realtime"
--protocol-type WEBSOCKET
--route-selection-expression '$request.body.action'
--query 'ApiId'
--output text

websocat -v ws://localhost:4510

Environment

- OS: ArchLinux
- LocalStack:
  LocalStack version: 4.8.1 (but received the same error with 4.6.0 and 4.7.0)
  LocalStack Docker image sha:
  LocalStack build date: 2025-09-16
  LocalStack build git hash: 7aa409536

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions