localstack / aws-sam-cli-local

Simple wrapper around AWS SAM CLI for use with LocalStack
Apache License 2.0
53 stars 11 forks source link

`samlocal sync` fails with `InvalidClientTokenId` when ` --watch` is used #9

Closed dantabel closed 3 months ago

dantabel commented 1 year ago

samlocal sync works fine when used without the --watch flag, but with the flag I get the following error after the initial sync completes:

$ samlocal sync --stack-name sam-app --watch

...

Stack update succeeded. Sync infra completed.

Infra sync completed.
Traceback (most recent call last):
  File "/home/dan/.local/bin/samlocal", line 81, in <module>
    main.cli()
  File "/home/dan/.local/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/dan/.local/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dan/.local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dan/.local/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 194, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 140, in wrapped
    return_value = func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/telemetry/event.py", line 287, in wrapped
    raise exception
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/telemetry/event.py", line 279, in wrapped
    return_value = func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 92, in wrapped
    return func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 104, in wrapped
    return func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 41, in wrapped
    actual_result = func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/cli/main.py", line 86, in wrapper
    return func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 38, in wrapped
    return func(*args, **kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/commands/sync/command.py", line 187, in cli
    do_cli(
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/commands/sync/command.py", line 350, in do_cli
    execute_watch(
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/commands/sync/command.py", line 454, in execute_watch
    watch_manager.start()
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 183, in start
    self._start()
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 195, in _start
    self._execute_infra_sync()
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 227, in _execute_infra_sync
    self._start_sync()
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 203, in _start_sync
    self._update_stacks()
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/watch_manager.py", line 115, in _update_stacks
    self._sync_flow_factory.load_physical_id_mapping()
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/sync_flow_factory.py", line 132, in load_physical_id_mapping
    raise ex
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/sync/sync_flow_factory.py", line 121, in load_physical_id_mapping
    resource_mapping = get_resource_summaries(
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/utils/cloudformation.py", line 90, in get_resource_summaries
    raise ex
  File "/home/dan/.local/lib/python3.8/site-packages/samcli/lib/utils/cloudformation.py", line 80, in get_resource_summaries
    cfn_resource_summaries = list(
  File "/home/dan/.local/lib/python3.8/site-packages/boto3/resources/collection.py", line 81, in __iter__
    for page in self.pages():
  File "/home/dan/.local/lib/python3.8/site-packages/boto3/resources/collection.py", line 171, in pages
    for page in pages:
  File "/home/dan/.local/lib/python3.8/site-packages/botocore/paginate.py", line 269, in __iter__
    response = self._make_request(current_kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/botocore/paginate.py", line 357, in _make_request
    return self._method(**current_kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/botocore/client.py", line 514, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/dan/.local/lib/python3.8/site-packages/botocore/client.py", line 938, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the ListStackResources operation: The security token included in the request is invalid.

There is no error in the localstack logs, so I assume that the CLI is trying to access the real AWS rather than the Local Stack when the --watch flag is used.

localstack 1.3.0 samlocal 1.66.0

dantabel commented 1 year ago

@bergera Could your PR possibly fix this issue? Could the above error be caused by the SAM CLI using an unmodified Client?

PR: https://github.com/localstack/aws-sam-cli-local/pull/5

whummer commented 1 year ago

Thanks for reporting @dantabel - a new version has been released now, can you please upgrade and give it another try?

pip install --upgrade 'aws-sam-cli-local>=1.67.0'

Thanks for your help!

lakkeger commented 10 months ago

Hi! We just wanted to follow up on our last message to see whether your issue has been resolved. Were you able to get it working with the latest version of LocalStack? We would appreciate your feedback!

lakkeger commented 3 months ago

Closing this issue due to inactivity.