Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: sam build shows Error: 500 Server Error for #7508

Closed
lufia opened this issue Sep 24, 2024 · 2 comments
Closed

Bug: sam build shows Error: 500 Server Error for #7508

lufia opened this issue Sep 24, 2024 · 2 comments
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@lufia
Copy link

lufia commented Sep 24, 2024

Description:

I have an issue with sam build.

Error: 500 Server Error for http+docker://localhost/v1.35/build?t=mylambdafunction%3Alatest&q=False&nocache=False&rm=True&forcerm=False&pull=False&dockerfile=.&platform=linux%2Famd64: Internal Server Error ("unexpected error reading Dockerfile: read /var/lib/docker/tmp/docker-builder1007095826: is a directory")

It is very similar to #6308 but the error message, maybe errno, is differ.

Steps to reproduce:

I can reproduce this with two files.

1. Dockerfile

FROM	postgres:15

2. template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Resources:
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      Architectures:
        - x86_64
      Events:
        MyAPI:
          Type: Api
          Properties:
            Path: /
            Method: GET
    Metadata:
      DockerContext: .
      Dockerfile: .

Outputs:
  ApiURL:
    Description: URL of the API
    Value: !GetAtt ApiURL.Arn

Observed result:

$ sam build --debug

2024-09-25 00:41:12,786 | No config file found in this directory.
2024-09-25 00:41:12,786 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/home/lufia/Downloads/sam/xx/samconfig.toml'
2024-09-25 00:41:12,786 | Config file location: /home/lufia/Downloads/sam/xx/samconfig.toml
2024-09-25 00:41:12,786 | Config file '/home/lufia/Downloads/sam/xx/samconfig.toml' does not exist
2024-09-25 00:41:12,787 | Using SAM Template at /home/lufia/Downloads/sam/xx/template.yaml
2024-09-25 00:41:12,800 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/home/lufia/Downloads/sam/xx/samconfig.toml'
2024-09-25 00:41:12,800 | Using config file: samconfig.toml, config environment: default
2024-09-25 00:41:12,800 | Expand command line arguments to:
2024-09-25 00:41:12,800 | --template_file=/home/lufia/Downloads/sam/xx/template.yaml --mount_with=READ --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache 
2024-09-25 00:41:12,824 | 'build' command is called
2024-09-25 00:41:12,825 | No Parameters detected in the template
2024-09-25 00:41:12,862 | There is no customer defined id or cdk path defined for resource MyLambdaFunction, so we will use the resource logical id as the resource id
2024-09-25 00:41:12,862 | 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
2024-09-25 00:41:12,863 | 0 stacks found in the template
2024-09-25 00:41:12,863 | No Parameters detected in the template
2024-09-25 00:41:12,874 | There is no customer defined id or cdk path defined for resource MyLambdaFunction, so we will use the resource logical id as the resource id
2024-09-25 00:41:12,874 | 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
2024-09-25 00:41:12,874 | 2 resources found in the stack 
2024-09-25 00:41:12,874 | Found Serverless function with name='MyLambdaFunction' and ImageUri='None'
2024-09-25 00:41:12,874 | --base-dir is not presented, adjusting uri . relative to /home/lufia/Downloads/sam/xx/template.yaml
2024-09-25 00:41:12,874 | --base-dir is not presented, adjusting uri . relative to /home/lufia/Downloads/sam/xx/template.yaml
2024-09-25 00:41:12,875 | 2 resources found in the stack 
2024-09-25 00:41:12,876 | Found Serverless function with name='MyLambdaFunction' and ImageUri='None'
2024-09-25 00:41:12,876 | Error occurred while trying to track an event: Event 'BuildFunctionRuntime' does not accept value 'None'.
2024-09-25 00:41:12,876 | Instantiating build definitions
2024-09-25 00:41:12,877 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(None, /home/lufia/Downloads/sam/xx, Image, , a5fae4d6-a071-48f5-b7c9-1b2500452402, {'DockerContext': '/home/lufia/Downloads/sam/xx', 'Dockerfile': '.'}, {}, x86_64, []), Function: Function({'function_id': 'MyLambdaFunction', 'name': 'MyLambdaFunction', 'functionname': 'MyLambdaFunction', 'runtime': None, 'memory': None, 'timeout': None, 'handler': None, 'imageuri': None, 'packagetype': 'Image', 'imageconfig': None, 'codeuri': '/home/lufia/Downloads/sam/xx', 'environment': None, 'rolearn': None, 'layers': [], 'events': {'MyAPI': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'GET', 'RestApiId': 'ServerlessRestApi'}}}, 'metadata': {'DockerContext': '/home/lufia/Downloads/sam/xx', 'Dockerfile': '.', 'SamResourceId': 'MyLambdaFunction'}, 'inlinecode': None, 'codesign_config_arn': None, 'architectures': ['x86_64'], 'function_url_config': None, 'function_build_info': <FunctionBuildInfo.BuildableImage: ('BuildableImage', 'Regular IMAGE function which can be build with SAM CLI')>, 'stack_path': '', 'runtime_management_config': None, 'logging_config': None}))
2024-09-25 00:41:12,878 | Building codeuri: /home/lufia/Downloads/sam/xx runtime: None architecture: x86_64 functions: MyLambdaFunction
2024-09-25 00:41:12,878 | Building to following folder /home/lufia/Downloads/sam/xx/.aws-sam/build/MyLambdaFunction
2024-09-25 00:41:12,878 | Building image for MyLambdaFunction function
2024-09-25 00:41:12,880 | Setting DockerBuildArgs for MyLambdaFunction function
2024-09-25 00:41:12,886 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-09-25 00:41:12,891 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-09-25 00:41:12,891 | Unable to find Click Context for getting session_id.
2024-09-25 00:41:12,891 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '30387b61-b8b6-43b9-abc4-c82d9a621f05', 'installationId': 'af4e5d08-e36d-4473-9826-fa2fe9740cfb', 'sessionId': 'cabca648-cde9-48f1-94da-090578f6bd16', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.10', 'samcliVersion': '1.124.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '5dde896887f6754c9b15bfe3a441ae4806df2fde94001311e08bf110622e0bbe', 'initialCommit': None}, 'duration': 86, 'exitReason': 'APIError', 'exitCode': 255}}]}
2024-09-25 00:41:12,891 | Sending Telemetry: {'metrics': [{'events': {'requestId': '74b7cc08-358e-4012-817b-1f7989f1bd3f', 'installationId': 'af4e5d08-e36d-4473-9826-fa2fe9740cfb', 'sessionId': 'cabca648-cde9-48f1-94da-090578f6bd16', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.10', 'samcliVersion': '1.124.0', 'commandName': 'sam build', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '12aeb39af1e94a01be28a684b6386580', 'time_stamp': '2024-09-24 15:41:12.786', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '5add3ea0cbd94edfbe284fcc766638f7', 'time_stamp': '2024-09-24 15:41:12.800', 'exception_name': None}]}}}]}
2024-09-25 00:41:13,349 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2024-09-25 00:41:13,352 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Error: 500 Server Error for http+docker://localhost/v1.35/build?t=mylambdafunction%3Alatest&q=False&nocache=False&rm=True&forcerm=False&pull=False&dockerfile=.&platform=linux%2Famd64: Internal Server Error ("unexpected error reading Dockerfile: read /var/lib/docker/tmp/docker-builder3124676323: is a directory")
Traceback:
  File "click/core.py", line 1078, in main
  File "click/core.py", line 1688, in invoke
  File "click/core.py", line 1434, in invoke
  File "click/core.py", line 783, in invoke
  File "samcli/cli/cli_config_file.py", line 347, in wrapper
  File "click/decorators.py", line 92, in new_func
  File "click/core.py", line 783, in invoke
  File "samcli/lib/telemetry/metric.py", line 185, in wrapped
  File "samcli/lib/telemetry/metric.py", line 150, in wrapped
  File "samcli/lib/utils/version_checker.py", line 43, in wrapped
  File "samcli/cli/main.py", line 95, in wrapper
  File "samcli/commands/build/command.py", line 169, in cli
  File "samcli/commands/build/command.py", line 258, in do_cli
  File "samcli/commands/build/build_context.py", line 284, in run
  File "samcli/lib/build/app_builder.py", line 226, in build
  File "samcli/lib/build/build_strategy.py", line 83, in build
  File "samcli/lib/build/build_strategy.py", line 93, in _build_functions
  File "samcli/lib/build/build_strategy.py", line 167, in build_single_function_definition
  File "samcli/lib/build/app_builder.py", line 671, in _build_function
  File "samcli/lib/build/app_builder.py", line 429, in _build_lambda_image
  File "docker/models/images.py", line 302, in build
  File "docker/utils/json_stream.py", line 60, in split_buffer
  File "docker/utils/json_stream.py", line 16, in stream_as_text
  File "docker/api/client.py", line 374, in _stream_helper
  File "docker/api/client.py", line 281, in _result
  File "docker/api/client.py", line 277, in _raise_for_status
  File "docker/errors.py", line 39, in create_api_error_from_http_exception

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

Expected result:

No errors.

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

  1. OS: Arch Linux
  2. sam --version: SAM CLI, version 1.124.0
  3. AWS region: not set
{
  "version": "1.124.0",
  "system": {
    "python": "3.11.10",
    "os": "Linux-6.10.10-arch1-1-x86_64-with-glibc2.40"
  },
  "additional_dependencies": {
    "docker_engine": "27.2.1",
    "aws_cdk": "Not available",
    "terraform": "1.9.6"
  },
  "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"
  ]
}

Add --debug flag to command you are running

@lufia lufia added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 24, 2024
@lufia
Copy link
Author

lufia commented Sep 24, 2024

I noticed I have wrong above YAML config.

Dockerfile: parameter expects a filename but I specified to "." directory.

@lufia lufia closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

1 participant