aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.52k stars 1.17k forks source link

sam sync doesn't work with WebSocket API Gateway - KeyError: 'AWS::ApiGatewayV2::Api' #3459

Closed theimowski closed 2 years ago

theimowski commented 3 years ago

Description:

I'm trying to get sam sync command working with a stack using WebSocket API Gateway.

Judging by the exception raised, API Gateway V2 seems to be unsupported by sam sync

Steps to reproduce:

  1. git clone https://github.com/aws-samples/simple-websockets-chat-app
  2. sam sync --stack-name test-sam-sync-ws --debug --watch

Observed result:

Stack is created properly, but afterwards the command fails:

2021-11-11 09:08:45 - Waiting for stack create/update to complete

CloudFormation events from stack operations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                           ResourceType                             LogicalResourceId                        ResourceStatusReason
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE_IN_PROGRESS                       AWS::CloudFormation::Stack               test-sam-sync-ws                         Transformation succeeded
UPDATE_IN_PROGRESS                       AWS::CloudFormation::Stack               AwsSamAutoDependencyLayerNestedStack     -
UPDATE_COMPLETE                          AWS::CloudFormation::Stack               AwsSamAutoDependencyLayerNestedStack     -
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS      AWS::CloudFormation::Stack               test-sam-sync-ws                         -
UPDATE_COMPLETE                          AWS::CloudFormation::Stack               AwsSamAutoDependencyLayerNestedStack     -
UPDATE_COMPLETE                          AWS::CloudFormation::Stack               test-sam-sync-ws                         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

CloudFormation outputs from deployed stack
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Outputs
------------------------------------------------------------------------------------------------------------------------------------------------------------------

(...)

------------------------------------------------------------------------------------------------------------------------------------------------------------------

2021-11-11 09:09:23,189 |
Stack update succeeded. Sync infra completed.

2021-11-11 09:09:23,189 | {'StackId': 'arn:aws:cloudformation:eu-central-1:<account-id>:stack/test-sam-sync-ws/58dc5700-4243-11ec-87f0-02bc731afc30', 'ResponseMetadata': {'RequestId': '20ce3e4b-ff60-4de2-9325-02f4370cd4bc', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '20ce3e4b-ff60-4de2-9325-02f4370cd4bc', 'content-type': 'text/xml', 'content-length': '389', 'date': 'Thu, 11 Nov 2021 08:08:45 GMT'}, 'RetryAttempts': 0}}
2021-11-11 09:09:23,224 | Collected default values for parameters: {'TableName': 'simplechat_connections'}
2021-11-11 09:09:23,254 | 16 stacks found in the template
2021-11-11 09:09:23,255 | Loading physical ID mapping
2021-11-11 09:09:23,255 | Fetching stack (test-sam-sync-ws) resources
2021-11-11 09:09:23,717 | Collected default values for parameters: {'TableName': 'simplechat_connections'}
2021-11-11 09:09:23,749 | Collected default values for parameters: {'TableName': 'simplechat_connections'}
2021-11-11 09:09:23,780 | Collected default values for parameters: {'TableName': 'simplechat_connections'}
2021-11-11 09:09:23,812 | Collected default values for parameters: {'TableName': 'simplechat_connections'}
2021-11-11 09:09:23,843 | Collected default values for parameters: {'TableName': 'simplechat_connections'}
2021-11-11 09:09:23,876 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '656539bf-6947-46b3-86e1-f7f90b2deee6', 'installationId': 'ca9087b1-e063-433b-8789-5807c2febe83', 'sessionId': 'f123b945-5b41-4e1b-a101-f473b5759339', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.12', 'samcliVersion': '1.35.0', 'awsProfileProvided': True, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam sync', 'duration': 49640, 'exitReason': 'KeyError', 'exitCode': 255}}]}
2021-11-11 09:09:24,533 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/Cellar/aws-sam-cli/1.35.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.35.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.35.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.35.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.35.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.35.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.35.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.35.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 157, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 122, in wrapped
    return_value = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 86, in wrapped
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 41, in wrapped
    actual_result = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/commands/sync/command.py", line 173, in cli
    do_cli(
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/commands/sync/command.py", line 316, in do_cli
    execute_watch(template_file, build_context, package_context, deploy_context, dependency_layer)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/commands/sync/command.py", line 415, in execute_watch
    watch_manager.start()
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 157, in start
    self._start()
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 169, in _start
    self._execute_infra_sync()
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 194, in _execute_infra_sync
    self._add_code_triggers()
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 113, in _add_code_triggers
    trigger = self._trigger_factory.create_trigger(resource_id, self._on_code_change_wrapper(resource_id))
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/code_trigger_factory.py", line 110, in create_trigger
    return cast(CodeTriggerFactory.GeneratorFunction, generator)(
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/code_trigger_factory.py", line 66, in _create_definition_code_trigger
    return DefinitionCodeTrigger(resource_identifier, resource_type, self._stacks, on_code_change)
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/resource_trigger.py", line 299, in __init__
    self._definition_file = self._get_definition_file()
  File "/usr/local/Cellar/aws-sam-cli/1.35.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/resource_trigger.py", line 314, in _get_definition_file
    property_name = RESOURCES_WITH_LOCAL_PATHS[self._resource_type][0]
KeyError: 'AWS::ApiGatewayV2::Api'

Expected result:

Command should work with WebSocket API Gateway

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

  1. OS: MacOS Catalina 10.15.7
  2. sam --version: 1.35.0
  3. AWS region: eu-central-1
semmgeorge commented 3 years ago

+ the same issue with SAM Accelerate when run 'sam sync' sam --version: 1.35.0

2021-11-12 18:26:01,094 | No Parameters detected in the template 2021-11-12 18:26:01,126 | 14 stacks found in the template 2021-11-12 18:26:01,126 | Loading physical ID mapping 2021-11-12 18:26:01,127 | Fetching stack (test-sam-sync-ws1) resources 2021-11-12 18:26:02,029 | No Parameters detected in the template 2021-11-12 18:26:02,059 | No Parameters detected in the template 2021-11-12 18:26:02,089 | No Parameters detected in the template 2021-11-12 18:26:02,119 | No Parameters detected in the template 2021-11-12 18:26:02,150 | No Parameters detected in the template 2021-11-12 18:26:02,181 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '55656c40-ed7c-4356-aa0d-2cd52a8bad14', 'installationId': '80aa4538-5361-4b52-8291-991d8aba6ae5', 'sessionId': '5f7bf416-045e-47b0-b04c-7418336ed800', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.7.10', 'samcliVersion': '1.35.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam sync', 'duration': 70558, 'exitReason': 'KeyError', 'exitCode': 255}}]} 2021-11-12 18:26:03,135 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) Traceback (most recent call last): File "samcli/main.py", line 12, in File "click/core.py", line 829, in call File "click/core.py", line 782, in main File "click/core.py", line 1259, in invoke File "click/core.py", line 1066, in invoke File "click/core.py", line 610, in invoke File "click/decorators.py", line 73, in new_func File "click/core.py", line 610, in invoke File "samcli/lib/telemetry/metric.py", line 157, in wrapped File "samcli/lib/telemetry/metric.py", line 122, in wrapped File "samcli/lib/cli_validation/image_repository_validation.py", line 85, in wrapped File "samcli/lib/telemetry/metric.py", line 86, in wrapped File "samcli/lib/utils/version_checker.py", line 41, in wrapped File "samcli/cli/main.py", line 87, in wrapper File "samcli/commands/sync/command.py", line 196, in cli File "samcli/commands/sync/command.py", line 316, in do_cli File "samcli/commands/sync/command.py", line 415, in execute_watch File "samcli/lib/sync/watch_manager.py", line 157, in start File "samcli/lib/sync/watch_manager.py", line 169, in _start File "samcli/lib/sync/watch_manager.py", line 194, in _execute_infra_sync File "samcli/lib/sync/watch_manager.py", line 113, in _add_code_triggers File "samcli/lib/utils/code_trigger_factory.py", line 111, in create_trigger File "samcli/lib/utils/code_trigger_factory.py", line 66, in _create_definition_code_trigger File "samcli/lib/utils/resource_trigger.py", line 299, in init File "samcli/lib/utils/resource_trigger.py", line 314, in _get_definition_file KeyError: 'AWS::ApiGatewayV2::Api' [30207] Failed to execute script main

wchengru commented 2 years ago

We can confirm that the AWS::ApiGatewayV2::Api is not resolved to S3 path. I will submit a pr for this.

moelasmar commented 2 years ago

The PR is released in SAM CLI V 1.37.0

theimowski commented 2 years ago

Thanks, I can confirm this is now fixed in 1.37 :+1:

Now that I've got that part working, I've found another issue with sam sync - will create a new case with details