aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Bug: sam build stuck at "Setting DockerBuildArgs for ..."

Open Dan2V opened this issue 7 months ago • 2 comments

Description:

The command 'sam build' is getting stuck at "Setting DockerBuildArgs for ". I have an application with many lambda functions, overall divided in two types. I highlighted with double* the differences between types A and B.

Type A follows the template:

myFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      MemorySize: 8000
      Timeout: 60
      Role: arn:aws:iam::.....
      Architectures:
        - x86_64
      Events:
        .....
    **Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./myFunctionFolder**

Type B follows the template:

myFunction:
    Type: AWS::Serverless::Function
    Properties:
      **CodeUri: my_function_folder/**
      PackageType: Image
      Timeout: 300
      Role: arn:aws:iam::......
      Architectures:
        - x86_64
      **Environment:
        ......**
      Events:
        ......
    **Metadata:
      Dockerfile: ./my_function_folder/Dockerfile
      DockerContext: ./**

Both were building with no issues up to yesterday. After no change at all, type B doesn't build anymore, getting stuck at "Setting DockerBuildArgs for " (worth noticing that I don't use DockerBuildArgs anywhere). Type A still builds normally.

I suspect SAM CLI got automatically updated (does it do that? like windows?). I remember weeks ago it complaining that it had available updates that I ignored, and it is no longer complaining.

Steps to reproduce:

See description

Observed result:

No error, just stuck at a specific point of the building process.

Expected result:

I expected the application to be built successfully as it was before.

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

{
  "version": "1.132.0",
  "system": {
    "python": "3.12.6",
    "os": "Windows-11-10.0.26100-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "28.1.1",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "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"
  ]
}

Dan2V avatar May 22 '25 17:05 Dan2V

Thank you for reporting the issue. Let me try to reproduce this issue. We'll try to reproduce the issue to confirm if there any bug from SAM cli that cause this issue.

In the meantime, do you mind

  1. Trying to build the same image using docker build directly?
  2. Note the is the size of your project directory when using DockerContext: ./?
  3. Adding .dockerignore file to exclude build artifacts?
  4. And lasting, trying with sam build --debug and share the log if permitted?

vicheey avatar Sep 13 '25 02:09 vicheey

@Dan2V Thanks for the detailed bug report with the template configurations! This looks like an interesting issue where Type B functions are hanging during the build process.

From what I can see, the key difference between your working Type A and stuck Type B functions appears to be the CodeUri property combined with how the DockerContext is set. Type B has CodeUri: my_function_folder/ with DockerContext: ./ while Type A omits CodeUri and uses DockerContext: ./myFunctionFolder. This suggests there might be some interaction between these properties that's causing SAM CLI to hang when setting up the Docker build arguments.

The fact that this started happening "after no change at all" and you mentioned SAM CLI might have auto-updated points to a possible regression in a recent SAM CLI version. The hanging at "Setting DockerBuildArgs" specifically suggests the issue might be in the code that processes the Metadata section and prepares Docker build parameters - likely somewhere in the build workflow where SAM CLI resolves the paths and constructs the Docker build context.

My hypothesis is that there could be a deadlock or infinite loop condition introduced in recent versions when SAM CLI tries to reconcile the CodeUri path with the DockerContext path for image-based functions. The code might be getting stuck trying to resolve relative paths or validate the build context when both properties are present in this particular configuration.

Could you run sam build --debug and share the full output? Even though it hangs, the debug logs should show us exactly which code path it's taking and where it's getting stuck. Also, it would be helpful to know what SAM CLI version you were running before (if you can check your command history or logs) - this would help narrow down which release introduced the regression. The fix would likely need to be in the Docker build argument resolution logic, possibly in the samcli/lib/build or samcli/commands/build modules where it processes the function metadata and constructs the build parameters.

dcabib avatar Oct 04 '25 13:10 dcabib