question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

local start-api unable to parse RouteKey of Websocket function

See original GitHub issue

Description:

sam local start-api throws a ValueError since it tries to parse its RouteKey as regular http api as far as I can understand.

Steps to reproduce:

Add a websocket api to template.yaml

Observed result:

Traceback (most recent call last): File “/usr/local/bin/sam”, line 33, in <module> sys.exit(load_entry_point(‘aws-sam-cli==1.17.0’, ‘console_scripts’, ‘sam’)()) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 829, in call return self.main(*args, **kwargs) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 782, in main rv = self.invoke(ctx) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 610, in invoke return callback(*args, **kwargs) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/decorators.py”, line 73, in new_func return ctx.invoke(f, obj, *args, **kwargs) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/click/core.py”, line 610, in invoke return callback(*args, **kwargs) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py”, line 152, in wrapped raise exception # pylint: disable=raising-bad-type File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py”, line 121, in wrapped return_value = func(*args, **kwargs) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py”, line 42, in wrapped actual_result = func(*args, **kwargs) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/commands/local/start_api/cli.py”, line 86, in cli do_cli( File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/commands/local/start_api/cli.py”, line 173, in do_cli service = LocalApiService(lambda_invoke_context=invoke_context, port=port, host=host, static_dir=static_dir) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/commands/local/lib/local_api_service.py”, line 37, in init self.api_provider = ApiProvider( File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/api_provider.py”, line 41, in init self.api = self._extract_api(self.resources) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/api_provider.py”, line 70, in _extract_api provider.extract_resources(resources, collector, cwd=self.cwd) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/cfn_api_provider.py”, line 69, in extract_resources self._extract_cfn_gateway_v2_route(resources, logical_id, resource, collector) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/cfn_api_provider.py”, line 263, in _extract_cfn_gateway_v2_route method, path = self._parse_route_key(route_key) File “/usr/local/Cellar/aws-sam-cli/1.17.0/libexec/lib/python3.8/site-packages/samcli/lib/providers/cfn_api_provider.py”, line 422, in _parse_route_key [method, path] = route_key.split() ValueError: not enough values to unpack (expected 2, got 1)

Expected result:

Start the local api.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS Catalina
  2. sam --version: SAM CLI, version 1.17.0
  3. AWS region: eu-west-1

Add --debug flag to command you are running

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
stevenyapcommented, Feb 26, 2021

I have the same exact issue too.

  # does not work
  RouteConnect:
    Type: AWS::ApiGatewayV2::Route
    DependsOn:
      - IntegrationConnect
    Properties:
      ApiId: !Ref WebsocketGateway
      RouteKey: $connect
      AuthorizationType: NONE
      Target: !Sub 'integrations/${IntegrationConnect}'

  # works but can't deploy
  RouteConnect:
    Type: AWS::ApiGatewayV2::Route
    DependsOn:
      - IntegrationConnect
    Properties:
      ApiId: !Ref WebsocketGateway
      RouteKey: 'POST /connect'
      AuthorizationType: NONE
      Target: !Sub 'integrations/${IntegrationConnect}'
1reaction
sgbasaranercommented, Mar 3, 2021

@sriram-mv can we remove blocked tag from this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running API Gateway locally - AWS Documentation
Start a local instance of API Gateway using the sam local start-api AWS SAM CLI command.
Read more >
How I can invoke locally my lambda using API Gatewat ...
It's been a while but I was able to find a project called aws-lambda-ws-server as a possible workaround for your use case which...
Read more >
Building a WebSocket Service with AWS Lambda & DynamoDB
A step-by-step process to implement persistent socket connections using AWS Lambda & DynamoDB.
Read more >
serverless | Noise | Page 28
Before you begin, here are a couple of the concepts of a WebSocket API in API Gateway. The first is a new resource...
Read more >
How To Test your AWS Lambda Locally with SAM - YouTube
AWS Lambda functions are extremely powerful FaaS components. In this video, I teach you how to use Serverless Application Model (SAM) cli to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found