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.51k stars 1.17k forks source link

Bug: sam sync - ClientError #5025

Closed Glydric closed 1 year ago

Glydric commented 1 year ago

Description:

I was deploy a lambda function using sam sync

I get this

Error: An error occurred (ValidationError) when calling the GetTemplateSummary operation: GetTemplateSummary cannot be called on stacks pending Transform.
Traceback:
  File "click/core.py", line 1055, in main
  File "click/core.py", line 1657, in invoke
  File "click/core.py", line 1404, in invoke
  File "click/core.py", line 760, in invoke
  File "click/decorators.py", line 84, in new_func
  File "click/core.py", line 760, in invoke
  File "samcli/lib/telemetry/metric.py", line 183, in wrapped
  File "samcli/lib/telemetry/metric.py", line 148, in wrapped
  File "samcli/lib/telemetry/event.py", line 294, in wrapped
  File "samcli/lib/telemetry/event.py", line 286, in wrapped
  File "samcli/lib/cli_validation/image_repository_validation.py", line 92, in wrapped
  File "samcli/lib/telemetry/metric.py", line 102, in wrapped
  File "samcli/lib/utils/version_checker.py", line 42, in wrapped
  File "samcli/cli/main.py", line 92, in wrapper
  File "samcli/commands/_utils/cdk_support_decorators.py", line 39, in wrapped
  File "samcli/commands/_utils/command_exception_handler.py", line 90, in wrapper_command_exception_handler
  File "samcli/commands/_utils/command_exception_handler.py", line 48, in _handle_client_errors
  File "samcli/commands/_utils/command_exception_handler.py", line 73, in wrapper_command_exception_handler
  File "samcli/commands/sync/command.py", line 212, in cli
  File "samcli/commands/sync/command.py", line 401, in do_cli
  File "samcli/commands/sync/command.py", line 444, in execute_infra_contexts
  File "samcli/lib/sync/infra_sync_executor.py", line 209, in execute_infra_sync
  File "samcli/commands/deploy/deploy_context.py", line 166, in run
  File "samcli/commands/deploy/deploy_context.py", line 287, in deploy
  File "samcli/lib/deploy/deployer.py", line 601, in sync
  File "botocore/client.py", line 530, in _api_call
  File "botocore/client.py", line 960, in _make_api_call

An unexpected error was encountered while executing "sam sync".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20sync%20-%20ClientError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20sync%20-%20ClientError
  1. OS: macos ventura 13.3
  2. sam --version: SAM CLI, version 1.79.0
  3. AWS region: eu-south-1

Paste the output of sam --info here

{
  "version": "1.79.0",
  "system": {
    "python": "3.8.13",
    "os": "macOS-13.3-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  }
}

Add --debug flag to command you are running

jfuss commented 1 year ago

@DevThoth Thanks for the report. Updating labels.

jfuss commented 1 year ago

@DevThoth Could you explain how you ran into this issue? Also, sam sync --watch may be useful to you, if you are running sam sync manually all the time.

Glydric commented 1 year ago

I then find you that the problem was caused by configuration template, if it is wrong the command will not warn but instead will throw an error

jfuss commented 1 year ago

@DevThoth I am not sure I follow. Are you saying that the template.yaml or whatever your CFN template is written in is invalid, you hit the above issue you reported?

Glydric commented 1 year ago

Yes, template.yaml was wrong and i find out creating a new from 0 and comparing the templates

jfuss commented 1 year ago

@DevThoth Understood. Thank you for the additional information. Does this error happen why you tried to do sync the first time or just during the process of editing and updating?

Just trying to make sure I fully understand all the conditions.

Glydric commented 1 year ago

First sync

jeffdlin1618 commented 1 year ago

i get the same error now

jfuss commented 1 year ago

This appears to be solved by https://github.com/aws/aws-sam-cli/pull/5152. I can't replicate the exact error above but was able to get a ValidationError thrown by providing an invalid template. Now the template exists safely without stacktrace with info on the error from CloudFormation.

Failed to create/update the stack: testing-5025, An error occurred (ValidationError) when calling the CreateStack operation: 1 validation error detected: Value '[AWS:lambda::Function]' at 'typeNameList' failed to satisfy constraint: Member must satisfy
constraint: [Member must have length less than or equal to 204, Member must have length greater than or equal to 10, Member must satisfy regular expression pattern: [A-Za-z0-9]{2,64}::[A-Za-z0-9]{2,64}::[A-Za-z0-9]{2,64}(::MODULE){0,1}]
Error: Failed to create/update the stack: testing-5025, An error occurred (ValidationError) when calling the CreateStack operation: 1 validation error detected: Value '[AWS:lambda::Function]' at 'typeNameList' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 204, Member must have length greater than or equal to 10, Member must satisfy regular expression pattern: [A-Za-z0-9]{2,64}::[A-Za-z0-9]{2,64}::[A-Za-z0-9]{2,64}(::MODULE){0,1}]

This should go out in our next release, so updating labels. You can try to use our nightly releases to confirm the latest works. Details can be found here

github-actions[bot] commented 1 year ago

Patch is released in v1.84.0. Closing

ookadoo commented 1 week ago

If anyone else gets here trying to search, add --stack-name [something], that worked for me. Apparently having default.global.parameters stack_name set doesn't matter. This is on SAM CLI version 1.125.0.