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

Bug: sam deploy - ValueError #6310

Closed kaihendry closed 8 months ago

kaihendry commented 9 months ago

Description:

Unable to deploy https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/sam

Steps to reproduce:

Checkout https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/sam

sam build && sam deploy --guided

Observed result:

❯ sam deploy --guided --debug
2023-11-21 18:05:55,799 | No config file found in this directory.
2023-11-21 18:05:55,801 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/hendry/sam/powertools-example/samconfig.toml'
2023-11-21 18:05:55,801 | Config file location: /Users/hendry/sam/powertools-example/samconfig.toml
2023-11-21 18:05:55,802 | Config file '/Users/hendry/sam/powertools-example/samconfig.toml' does not exist
2023-11-21 18:05:55,812 | Using SAM Template at /Users/hendry/sam/powertools-example/.aws-sam/build/template.yaml
2023-11-21 18:05:55,838 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/hendry/sam/powertools-example/samconfig.toml'
2023-11-21 18:05:55,848 | Using config file: samconfig.toml, config environment: default
2023-11-21 18:05:55,849 | Expand command line arguments to:
2023-11-21 18:05:55,849 | --guided --template_file=/Users/hendry/sam/powertools-example/.aws-sam/build/template.yaml --fail_on_empty_changeset --on_failure=ROLLBACK --stack_name=sam-app
2023-11-21 18:05:55,972 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getAllItemsFunction is getAllItemsFunction
2023-11-21 18:05:55,973 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getByIdFunction is getByIdFunction
2023-11-21 18:05:55,973 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getUuidFunction is getUuidFunction
2023-11-21 18:05:55,974 | There is no customer defined id or cdk path defined for resource uuidApiUrlParameter, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,974 | Sam customer defined id is more priority than other IDs. Customer defined id for resource putItemFunction is putItemFunction
2023-11-21 18:05:55,974 | There is no customer defined id or cdk path defined for resource SampleTable, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,975 | There is no customer defined id or cdk path defined for resource apiGateway, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,975 | There is no customer defined id or cdk path defined for resource apiGatewayDeployment, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,976 | There is no customer defined id or cdk path defined for resource apiGatewayRootMethod, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,976 | There is no customer defined id or cdk path defined for resource lambdaApiGatewayInvoke, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,976 | There is no customer defined id or cdk path defined for resource lambdaIAMRole, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,977 | There is no customer defined id or cdk path defined for resource lambdaLogGroup, so we will use the resource logical id as the resource id
2023-11-21 18:05:55,977 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/hendry/sam/powertools-example/samconfig.toml'
2023-11-21 18:05:55,978 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/hendry/sam/powertools-example/samconfig.toml'

Configuring SAM deploy
======================

        Looking for config file [samconfig.toml] :  Not found

        Setting default arguments for 'sam deploy'
        =========================================
        Stack Name [sam-app]: powertools-ts
        AWS Region [us-east-1]: eu-west-2
        Parameter apiGatewayName [uuid-api]:
        Parameter apiGatewayStageName [dev]:
        Parameter apiGatewayHTTPMethod [GET]:
        Parameter lambdaFunctionName [uuid-lambda]:
2023-11-21 18:06:09,550 | Collected default values for parameters: {'apiGatewayName': 'uuid-api', 'apiGatewayStageName': 'dev', 'apiGatewayHTTPMethod': 'GET', 'lambdaFunctionName': 'uuid-lambda'}
2023-11-21 18:06:09,571 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getAllItemsFunction is getAllItemsFunction
2023-11-21 18:06:09,572 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getByIdFunction is getByIdFunction
2023-11-21 18:06:09,572 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getUuidFunction is getUuidFunction
2023-11-21 18:06:09,573 | There is no customer defined id or cdk path defined for resource uuidApiUrlParameter, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,573 | Sam customer defined id is more priority than other IDs. Customer defined id for resource putItemFunction is putItemFunction
2023-11-21 18:06:09,574 | There is no customer defined id or cdk path defined for resource SampleTable, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,574 | There is no customer defined id or cdk path defined for resource apiGateway, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,575 | There is no customer defined id or cdk path defined for resource apiGatewayDeployment, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,575 | There is no customer defined id or cdk path defined for resource apiGatewayRootMethod, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,575 | There is no customer defined id or cdk path defined for resource lambdaApiGatewayInvoke, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,576 | There is no customer defined id or cdk path defined for resource lambdaIAMRole, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,576 | There is no customer defined id or cdk path defined for resource lambdaLogGroup, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,577 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-11-21 18:06:09,578 | Unable to resolve property lambdaArn: OrderedDict({'Fn::GetAtt': ['getUuidFunction', 'Arn']}). Leaving as is.
2023-11-21 18:06:09,579 | Unable to resolve property Uri: OrderedDict({'Fn::Sub': ['arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations', OrderedDict({'lambdaArn': OrderedDict({'Fn::GetAtt':
['getUuidFunction', 'Arn']})})]}). Leaving as is.
2023-11-21 18:06:09,580 | Unable to resolve property FunctionName: OrderedDict({'Fn::GetAtt': ['getUuidFunction', 'Arn']}). Leaving as is.
2023-11-21 18:06:09,580 | 0 stacks found in the template
        #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
        Confirm changes before deploy [y/N]:
        #SAM needs permission to be able to create roles to connect to the resources in your template
        Allow SAM CLI IAM role creation [Y/n]: y
        #Preserves the state of previously provisioned resources when an operation fails
        Disable rollback [y/N]: y
2023-11-21 18:06:17,097 | Collected default values for parameters: {'apiGatewayName': 'uuid-api', 'apiGatewayStageName': 'dev', 'apiGatewayHTTPMethod': 'GET', 'lambdaFunctionName': 'uuid-lambda'}
2023-11-21 18:06:17,117 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getAllItemsFunction is getAllItemsFunction
2023-11-21 18:06:17,118 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getByIdFunction is getByIdFunction
2023-11-21 18:06:17,118 | Sam customer defined id is more priority than other IDs. Customer defined id for resource getUuidFunction is getUuidFunction
2023-11-21 18:06:17,119 | There is no customer defined id or cdk path defined for resource uuidApiUrlParameter, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,119 | Sam customer defined id is more priority than other IDs. Customer defined id for resource putItemFunction is putItemFunction
2023-11-21 18:06:17,120 | There is no customer defined id or cdk path defined for resource SampleTable, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,121 | There is no customer defined id or cdk path defined for resource apiGateway, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,121 | There is no customer defined id or cdk path defined for resource apiGatewayDeployment, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,122 | There is no customer defined id or cdk path defined for resource apiGatewayRootMethod, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,123 | There is no customer defined id or cdk path defined for resource lambdaApiGatewayInvoke, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,123 | There is no customer defined id or cdk path defined for resource lambdaIAMRole, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,124 | There is no customer defined id or cdk path defined for resource lambdaLogGroup, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,124 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-11-21 18:06:17,126 | Unable to resolve property lambdaArn: OrderedDict({'Fn::GetAtt': ['getUuidFunction', 'Arn']}). Leaving as is.
2023-11-21 18:06:17,127 | Unable to resolve property Uri: OrderedDict({'Fn::Sub': ['arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations', OrderedDict({'lambdaArn': OrderedDict({'Fn::GetAtt':
['getUuidFunction', 'Arn']})})]}). Leaving as is.
2023-11-21 18:06:17,128 | Unable to resolve property FunctionName: OrderedDict({'Fn::GetAtt': ['getUuidFunction', 'Arn']}). Leaving as is.
2023-11-21 18:06:17,128 | 13 resources found in the stack
2023-11-21 18:06:17,129 | Found Serverless function with name='getAllItemsFunction' and CodeUri='getAllItemsFunction'
2023-11-21 18:06:17,129 | --base-dir is not presented, adjusting uri getAllItemsFunction relative to /Users/hendry/sam/powertools-example/.aws-sam/build/template.yaml
2023-11-21 18:06:17,130 | Found Serverless function with name='getByIdFunction' and CodeUri='getByIdFunction'
2023-11-21 18:06:17,131 | --base-dir is not presented, adjusting uri getByIdFunction relative to /Users/hendry/sam/powertools-example/.aws-sam/build/template.yaml
2023-11-21 18:06:17,131 | Found Serverless function with name='getUuidFunction' and CodeUri='getUuidFunction'
2023-11-21 18:06:17,132 | --base-dir is not presented, adjusting uri getUuidFunction relative to /Users/hendry/sam/powertools-example/.aws-sam/build/template.yaml
2023-11-21 18:06:17,132 | Found Serverless function with name='putItemFunction' and CodeUri='putItemFunction'
2023-11-21 18:06:17,133 | --base-dir is not presented, adjusting uri putItemFunction relative to /Users/hendry/sam/powertools-example/.aws-sam/build/template.yaml
2023-11-21 18:06:17,133 | Detected Inline Swagger definition
2023-11-21 18:06:17,133 | Auth checks done on swagger are not exhaustive!
2023-11-21 18:06:17,134 | Detected Inline Swagger definition
2023-11-21 18:06:17,134 | Auth checks done on swagger are not exhaustive!
2023-11-21 18:06:17,135 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-11-21 18:06:17,255 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-11-21 18:06:17,256 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'c6dadcf9-dbcd-47f1-abe7-f6735caf9645', 'installationId': '101671f5-d4c6-4a3b-b2bc-8241e6ebe08d', 'sessionId':
'b88b446a-ff6c-48d4-a9ed-2f4c9aced421', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.0', 'samcliVersion': '1.103.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam deploy',
'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '93705d2dd3c0a0bd6c274c9ed8f2303cb04f12c9611f642cc0cea48030f99391', 'initialCommit': None}, 'duration': 21286, 'exitReason': 'ValueError', 'exitCode':
255}}]}
2023-11-21 18:06:17,256 | Unable to find Click Context for getting session_id.
2023-11-21 18:06:17,259 | Sending Telemetry: {'metrics': [{'events': {'requestId': '45243957-4319-4725-9262-cba87d4f23ef', 'installationId': '101671f5-d4c6-4a3b-b2bc-8241e6ebe08d', 'sessionId': 'b88b446a-ff6c-48d4-a9ed-2f4c9aced421',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.0', 'samcliVersion': '1.103.0', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml',
'thread_id': '2b400cfeeec14175975d20bd0c0069df', 'time_stamp': '2023-11-21 18:05:55.801', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '775c372b3a364a2f88719239ebdc2931',
'time_stamp': '2023-11-21 18:05:55.838', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '5381fb861a0945afa5538b739cfbe599', 'time_stamp': '2023-11-21 18:05:55.978',
'exception_name': None}]}}}]}
2023-11-21 18:06:17,743 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2023-11-21 18:06:17,746 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Error: Require value for either DefinitionBody or DefinitionUri
Traceback:
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/cli/cli_config_file.py", line 347, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/lib/cli_validation/image_repository_validation.py", line 110, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/click/decorators.py", line 92, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
    raise exception  # pylint: disable=raising-bad-type
    ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
    return_value = func(*args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
    actual_result = func(*args, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/cli/main.py", line 95, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/_utils/cdk_support_decorators.py", line 39, in wrapped
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/_utils/command_exception_handler.py", line 88, in wrapper_command_exception_handler
    raise ex
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/_utils/command_exception_handler.py", line 68, in wrapper_command_exception_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/command.py", line 200, in cli
    do_cli(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/command.py", line 294, in do_cli
    guided_context.run()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/guided_context.py", line 576, in run
    self.guided_prompts(_parameter_override_keys)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/guided_context.py", line 165, in guided_prompts
    self.prompt_authorization(stacks)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/guided_context.py", line 222, in prompt_authorization
    auth_required_per_resource = auth_per_resource(stacks)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/auth_utils.py", line 39, in auth_per_resource
    _auth_resource_event(sam_function_provider, sam_function, _auth_per_resource)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/auth_utils.py", line 73, in _auth_resource_event
    elif _auth_id(
         ^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/auth_utils.py", line 107, in _auth_id
    _auth_definition_body_and_uri(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/deploy/auth_utils.py", line 133, in _auth_definition_body_and_uri
    reader = SwaggerReader(definition_body=definition_body, definition_uri=definition_uri)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/aws-sam-cli/1.103.0/libexec/lib/python3.12/site-packages/samcli/commands/local/lib/swagger/reader.py", line 91, in __init__
    raise ValueError("Require value for either DefinitionBody or DefinitionUri")

An unexpected error was encountered while executing "sam deploy".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20deploy%20-%20ValueError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20deploy%20-%20ValueError

Expected result:

For it to deploy smoothly

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

❯ sam --info
{
  "version": "1.103.0",
  "system": {
    "python": "3.12.0",
    "os": "macOS-14.1.1-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "1.5.7"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}
mildaniel commented 9 months ago

Hey @kaihendry, thanks for reporting. It seems that are a couple things happening here that need to be addressed and I will mark this as a bug.

  1. It seems as though SAM CLI is expecting the implicit API to reference a Serverless API resource instead of an API Gateway API resource although the latter is valid too. We should handle this case appropriately.
  2. We raise a ValueError here which we shouldn't be doing.

In the meantime, can you try running sam deploy without the guided flow. It should bypass this check and the deployment should succeed.

am29d commented 9 months ago

Hey, Alex from Powertools TypeScript team here. I can confirm that sam deploy without guided works on the same project. The command I used was:

sam deploy --stack-name test --resolve-s3 --capabilities CAPABILITY_IAM
github-actions[bot] commented 8 months ago

Patch is released in v1.107.0. Closing