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: AWS SAM and Terraform build error #4902

Closed
mcorcoran opened this issue Mar 21, 2023 · 7 comments
Closed

Bug: AWS SAM and Terraform build error #4902

mcorcoran opened this issue Mar 21, 2023 · 7 comments
Labels
area/terraform terraform support issue type/duplicate type/feature Feature request

Comments

@mcorcoran
Copy link

mcorcoran commented Mar 21, 2023

Description:

I created a new hello world repo and ran the following command:

sam build --hook-name terraform --beta-features --use-container --build-image local-build-nodejs16.x --debug

SAM returns the following:
OSError: [Errno 2] No such file or directory

If I running the following on it's own however it completes successfully:

python ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py" --expression "|values|root_module|resources|[?address==\"null_resource.sam_metadata_lambda\"]|values|triggers|built_output_path" -y "/tmp/samcli/artifacts" --target "null_resource.sam_metadata_lambda"

Executes successfully however.

Steps to reproduce:

Directory Structure:
|->dist
|->src
      |->index.src
|->terraform
      |->main.tf

main.tf contents:

provider "aws" {
  region = "us-east-1"
}
provider "archive" {}
data "archive_file" "zip" {
  type        = "zip"
  source_dir  = "../src/"
  output_path = "../dist/index.zip"
}
resource "aws_lambda_function" "lambda" {
  function_name    = "index"
  filename         = data.archive_file.zip.output_path
  source_code_hash = data.archive_file.zip.output_base64sha256
  role             = "ARNROLE"
  handler          = "index.lambda_handler"
  runtime          = "nodejs16.x"
}

resource "null_resource" "sam_metadata_lambda" {
  triggers = {
    resource_name        = "aws_lambda_function.lambda"
    resource_type        = "ZIP_LAMBDA_FUNCTION"
    original_source_code = "../src/index.js"
    built_output_path    = "../dist/index.zip"
  }
  depends_on = [
    aws_lambda_function.lambda,
    data.archive_file.zip
  ]
}

Observed result:

2023-03-20 14:56:06,720 | Config file location: C:\Project Area\aws-sam-local\terraform\samconfig.toml
2023-03-20 14:56:06,721 | Config file 'C:\Project Area\aws-sam-local\terraform\samconfig.toml' does not exist
2023-03-20 14:56:06,721 | Looking for internal hook package
2023-03-20 14:56:06,722 | Loaded internal hook package "terraform"
2023-03-20 14:56:06,734 | --beta-features flag is enabled, enabling experimental flag.
2023-03-20 14:56:06,735 |
Experimental features are enabled for this session.
Visit the docs page to learn more about the AWS Beta terms https://aws.amazon.com/service-terms/.

2023-03-20 14:56:06,736 | Running Prepare Hook to prepare the current application
2023-03-20 14:56:06,738 | Executing prepare hook of hook "terraform"
2023-03-20 14:56:06,761 | Normalize the project root directory path C:\Project Area\aws-sam-local\terraform
2023-03-20 14:56:06,761 | Normalize the OutputDirPath C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata
2023-03-20 14:56:06,761 | Initializing Terraform application
2023-03-20 14:56:06,950 | 
2023-03-20 14:56:06,951 | Initializing the backend...
2023-03-20 14:56:07,943 | 
2023-03-20 14:56:07,944 | Initializing provider plugins...
2023-03-20 14:56:07,944 | - Reusing previous version of hashicorp/aws from the dependency lock file
2023-03-20 14:56:08,274 | - Reusing previous version of hashicorp/archive from the dependency lock file
2023-03-20 14:56:08,422 | - Reusing previous version of hashicorp/null from the dependency lock file
2023-03-20 14:56:09,484 | - Using previously-installed hashicorp/aws v4.59.0
2023-03-20 14:56:09,519 | - Using previously-installed hashicorp/archive v2.3.0
2023-03-20 14:56:09,560 | - Using previously-installed hashicorp/null v3.2.1
2023-03-20 14:56:09,562 | 
2023-03-20 14:56:09,562 | Terraform has been successfully initialized!
2023-03-20 14:56:09,562 |
2023-03-20 14:56:09,562 | You may now begin working with Terraform. Try running "terraform plan" to see
2023-03-20 14:56:09,562 | any changes that are required for your infrastructure. All Terraform commands
2023-03-20 14:56:09,563 | should now work.
2023-03-20 14:56:09,563 |
2023-03-20 14:56:09,563 | If you ever set or change modules or backend configuration for Terraform,
2023-03-20 14:56:09,563 | rerun this command to reinitialize your working directory. If you forget, other
2023-03-20 14:56:09,563 | commands will detect it and remind you to do so if necessary.

2023-03-20 14:56:09,568 | Creating terraform plan and getting JSON output
2023-03-20 14:56:16,777 | data.archive_file.zip: Reading...
2023-03-20 14:56:16,786 | data.archive_file.zip: Read complete after 0s [id=f839d55c3aed5b0fa5e14d0567eb1a6308ef7c88]
2023-03-20 14:56:17,447 | aws_lambda_function.lambda: Refreshing state... [id=index]
2023-03-20 14:56:18,130 | null_resource.sam_metadata_lambda: Refreshing state... [id=1033163272647498557]
2023-03-20 14:56:18,165 | 
2023-03-20 14:56:18,165 | No changes. Your infrastructure matches the configuration.
2023-03-20 14:56:18,166 |
2023-03-20 14:56:18,166 | Terraform has compared your real infrastructure against your configuration
2023-03-20 14:56:18,166 | and found no differences, so no changes are needed.

2023-03-20 14:56:24,479 | Generating metadata file
2023-03-20 14:56:24,479 | Mapping Lambda functions to their corresponding layers.
2023-03-20 14:56:24,480 | Parsing module:` root
2023-03-20 14:56:24,480 | Parsing module variables
2023-03-20 14:56:24,480 | Parsing module resources
2023-03-20 14:56:24,480 | Parsing module outputs
2023-03-20 14:56:24,480 | Parsing module calls
2023-03-20 14:56:24,481 | Processing resource aws_lambda_function.lambda
2023-03-20 14:56:24,481 | Mapping S3 object sources to corresponding functions
2023-03-20 14:56:24,481 | Linking layers for Lambda function aws_lambda_function.lambda
2023-03-20 14:56:24,481 | Link function configuration aws_lambda_function.lambda layer that has these instances [{'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'index', 'Architectures64'], 'Code': '../dist/index.zip', 'Handler': 'index.lambda_handler', 'PackageType': 'Zip', 'Runtime': 'nodejs16.x', 'Layers': [], 'Timeout': 3}, 'Metadata': {'SamResourceId': 'aws_lambda_function.lambpBuild': True}}].
2023-03-20 14:56:24,482 | Resolving resource attribute for resource (aws_lambda_function.lambda) and attribute (layers)
2023-03-20 14:56:24,482 | The value of the attribute layers is None for resource aws_lambda_function.lambda
2023-03-20 14:56:24,482 | The resolved layers for function aws_lambda_function.lambda are []
2023-03-20 14:56:24,483 | Map the resolved layers [] to configuration function aws_lambda_function.lambda.
2023-03-20 14:56:24,483 | There are no layers defined for lambda function aws_lambda_function.lambda
2023-03-20 14:56:24,483 | Enrich the mapped resources with the sam metadata information and generate Makefile
2023-03-20 14:56:24,520 | Check if the input resource name aws_lambda_function.lambda is a postfix to the current module address None
2023-03-20 14:56:24,520 | check if the resource address aws_lambda_function.lambda has a relevant cfn resource or not
2023-03-20 14:56:24,520 | The CFN resource that match the input resource name aws_lambda_function.lambda is AwsLambdaFunctionLambda411132D8
2023-03-20 14:56:24,521 | Enrich the ZIP lambda function AwsLambdaFunctionLambda411132D8 using the metadata properties defined in resource null_resource.sam_metadata_lambda
2023-03-20 14:56:24,521 | Validate if the referenced resource in sam metadata resource null_resource.sam_metadata_lambda is of the expected type ZIP_LAMBDA_FUNCTION
2023-03-20 14:56:24,521 | Extract the source code from the sam metadata resource null_resource.sam_metadata_lambda from property original_source_code
2023-03-20 14:56:24,522 | The found source code value is ../src/index.js and property value is None
2023-03-20 14:56:24,522 | Try to decode the source code value in case if it is a encoded JSON string.
2023-03-20 14:56:24,522 | Source code value could not be parsed as a JSON object. Handle it as normal string value
2023-03-20 14:56:24,522 | The source code path value is ../src/index.js
2023-03-20 14:56:24,523 | The source code path value is not absoulte value. Get the absolute value based on the root directory C:\Project Area\aws-sam-local\terraform
2023-03-20 14:56:24,523 | The calculated absolute path of source code is C:\Project Area\aws-sam-local\src\index.js
2023-03-20 14:56:24,524 | Generate Makefile in C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata
2023-03-20 14:56:24,530 | Finished generating metadata file. Storing in C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata\template.json
2023-03-20 14:56:24,531 | Metadata file location - C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata\template.json
2023-03-20 14:56:24,532 | Prepare hook completed and metadata file generated at: C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata\template.json
2023-03-20 14:56:24,533 | Using SAM Template at C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata\template.json
2023-03-20 14:56:24,659 | Using config file: samconfig.toml, config environment: default
2023-03-20 14:56:24,659 | Expand command line arguments to:
2023-03-20 14:56:24,659 | --template_file=C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata\template.json --hook_name=terraform --use_container --build_image=('DOCKERIMAGE',) --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache
2023-03-20 14:56:25,224 | 'build' command is called
2023-03-20 14:56:25,224 | Starting Build inside a container
2023-03-20 14:56:25,225 | No Parameters detected in the template
2023-03-20 14:56:25,250 | Sam customer defined id is more priority than other IDs. Customer defined id for resource AwsLambdaFunctionLambda411132D8 is aws_lambda_function.lambda
2023-03-20 14:56:25,250 | 0 stacks found in the template
2023-03-20 14:56:25,251 | No Parameters detected in the template
2023-03-20 14:56:25,267 | Sam customer defined id is more priority than other IDs. Customer defined id for resource AwsLambdaFunctionLambda411132D8 is aws_lambda_function.lambda
2023-03-20 14:56:25,268 | 1 resources found in the stack
2023-03-20 14:56:25,268 | Found Lambda function with name='AwsLambdaFunctionLambda411132D8' and CodeUri='C:\Project Area\aws-sam-local\src\index.js'
2023-03-20 14:56:25,268 | --base-dir is not presented, adjusting uri C:\Project Area\aws-sam-local\src\index.js relative to C:\Project Area\aws-sam-local\terraform\.aws-sam-iacs\iacs_metadata\template.
2023-03-20 14:56:25,271 | 1 resources found in the stack
2023-03-20 14:56:25,271 | Found Lambda function with name='AwsLambdaFunctionLambda411132D8' and CodeUri='C:\Project Area\aws-sam-local\src\index.js'
2023-03-20 14:56:25,272 | Instantiating build definitions
2023-03-20 14:56:25,287 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(nodejs16.x, C:\Project Area\aws-sam-local\src\index.js, Zip, , 705741a2-f5c4--306511b99213, {'SkipBuild': False, 'BuildMethod': 'makefile', 'ContextPath': 'C:\\Project Area\\aws-sam-local\\terraform\\.aws-sam-iacs\\iacs_metadata', 'WorkingDirectory': 'C:\\Project Area\\aws-sam-rraform', 'ProjectRootDirectory': 'C:\\Project Area\\aws-sam-local\\terraform'}, {}, x86_64, []), Function: Function(function_id='aws_lambda_function.lambda', name='AwsLambdaFunctionLambda411132D8', fue='index', runtime='nodejs16.x', memory=None, timeout=3, handler='index.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\\Project Area\\aws-sam-local\\src\\index.js', en=None, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'aws_lambda_function.lambda', 'SkipBuild': False, 'BuildMethod': 'makefile', 'ContextPath': 'C:\\Project Area\\aws-sam-local\\teraws-sam-iacs\\iacs_metadata', 'WorkingDirectory': 'C:\\Project Area\\aws-sam-local\\terraform', 'ProjectRootDirectory': 'C:\\Project Area\\aws-sam-local\\terraform'}, inlinecode=None, codesign_config_a
architectures=['x86_64'], function_url_config=None, stack_path='', runtime_management_config=None))
2023-03-20 14:56:25,290 | Building codeuri: C:\Project Area\aws-sam-local\src\index.js runtime: nodejs16.x metadata: {'SkipBuild': False, 'BuildMethod': 'makefile', 'ContextPath': 'C:\\Project Area\\awal\\terraform\\.aws-sam-iacs\\iacs_metadata', 'WorkingDirectory': 'C:\\Project Area\\aws-sam-local\\terraform', 'ProjectRootDirectory': 'C:\\Project Area\\aws-sam-local\\terraform'} architecture: x86_6ns: aws_lambda_function.lambda
2023-03-20 14:56:25,292 | Building to following folder C:\Project Area\aws-sam-local\terraform\.aws-sam\build\AwsLambdaFunctionLambda411132D8

Fetching docker-sbx-frameworkimage-rel.dvllb.travp.net/ecr.aws/sam/build-nodejs16.x Docker container image......
2023-03-20 14:56:26,413 | Mounting C:\Project Area\aws-sam-local\terraform as /tmp/samcli/source:ro,delegated inside runtime container
Using the request object from command line argument
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Running workflow 'CustomMakeBuilder'
Running CustomMakeBuilder:CopySource
File (.aws-sam) is in ignored set, skipping it
Creating target folders at /tmp/samcli/scratch/.aws-sam-iacs
Copying directory metadata from source (/tmp/samcli/source/.aws-sam-iacs) to destination (/tmp/samcli/scratch/.aws-sam-iacs)
Creating target folders at /tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata
Copying directory metadata from source (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/Makefile) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/Makefile)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/template.json) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/template.json)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/z_samcli_backend_override) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/z_samcli_backend_override)
Creating target folders at /tmp/samcli/scratch/.terraform
Copying directory metadata from source (/tmp/samcli/source/.terraform) to destination (/tmp/samcli/scratch/.terraform)
Creating target folders at /tmp/samcli/scratch/.terraform/providers
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers) to destination (/tmp/samcli/scratch/.terraform/providers)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/harchive)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraforicorp/archive/2.3.0)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64) to destination (/tmp/samcli/scratch/.terraform/providers/regraform.io/hashicorp/archive/2.3.0/windows_amd64)
Copying source file (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64/terraform-provider-archive_v2.3.0_x5.exe) to destination (/tmp/samcli/scratch/.tproviders/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64/terraform-provider-archive_v2.3.0_x5.exe)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashiCreating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.irp/aws/4.59.0)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64) to destination (/tmp/samcli/scratch/.terraform/providers/registorm.io/hashicorp/aws/4.59.0/windows_amd64)
Copying source file (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64/terraform-provider-aws_v4.59.0_x5.exe) to destination (/tmp/samcli/scratch/.terrafoers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64/terraform-provider-aws_v4.59.0_x5.exe)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashl)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.irp/null/3.2.1)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64) to destination (/tmp/samcli/scratch/.terraform/providers/registorm.io/hashicorp/null/3.2.1/windows_amd64)
Copying source file (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64/terraform-provider-null_v3.2.1_x5.exe) to destination (/tmp/samcli/scratch/.terrafoers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64/terraform-provider-null_v3.2.1_x5.exe)
Copying source file (/tmp/samcli/source/.terraform/terraform.tfstate) to destination (/tmp/samcli/scratch/.terraform/terraform.tfstate)
Copying source file (/tmp/samcli/source/.terraform.lock.hcl) to destination (/tmp/samcli/scratch/.terraform.lock.hcl)
Copying source file (/tmp/samcli/source/28056a2b-9e53-4d26-86ad-c48e0deae426.tfstate) to destination (/tmp/samcli/scratch/28056a2b-9e53-4d26-86ad-c48e0deae426.tfstate)
Copying source file (/tmp/samcli/source/28056a2b-9e53-4d26-86ad-c48e0deae426.tfstate.backup) to destination (/tmp/samcli/scratch/28056a2b-9e53-4d26-86ad-c48e0deae426.tfstate.backup)
Copying source file (/tmp/samcli/source/env-file.json) to destination (/tmp/samcli/scratch/env-file.json)
Copying source file (/tmp/samcli/source/main.tf) to destination (/tmp/samcli/scratch/main.tf)
Copying source file (/tmp/samcli/source/package-lock.json) to destination (/tmp/samcli/scratch/package-lock.json)
Copying source file (/tmp/samcli/source/package.json) to destination (/tmp/samcli/scratch/package.json)
Copying source file (/tmp/samcli/source/z_samcli_backend_override.tf) to destination (/tmp/samcli/scratch/z_samcli_backend_override.tf)
CustomMakeBuilder:CopySource succeeded
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /tmp/samcli/artifacts
executing Make: ['make', '--makefile', '/tmp/samcli/manifest/Makefile', 'build-AwsLambdaFunctionLambda411132D8']
python ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py" --expression "|values|root_module|resources|[?address==\"null_resource.sam_metadata_lambda\"]|values|triggers|built_output_path" -y "/tmp/samcli/artifacts" --target "null_resource.sam_metadata_lambda"
CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 111, in execute
    cwd=self.working_directory,
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/make.py", line 93, in run
    raise MakeExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 301, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 114, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1
Builder workflow failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 111, in execute
    cwd=self.working_directory,
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/make.py", line 93, in run
    raise MakeExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 301, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 114, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/__main__.py", line 133, in main
    experimental_flags=params.get("experimental_flags", []),
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/builder.py", line 164, in build
    return workflow.run()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 95, in wrapper
    func(self, *args, **kwargs)
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 308, in run
    raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: CustomMakeBuilder:MakeBuild - Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
 \"-reconfigure\", \"-input=false\", \"-force-copy\"])\n  File \"/usr/lib64/python2.7/subprocess.py\", line 185, in check_call\n    retcode = call(*popenargs, **kwargs)\n  File \"/usr/lib64/python2.7/s
 \"-reconfigure\", \"-input=false\", \"-force-copy\"])\n  File \"/usr/lib64/python2.7/subprocess.py\", line 185, in check_call\n    retcode = call(*popenargs, **kwargs)\n  File \"/usr/lib64/python2.7/sck_call\n    retcode = call(*popenargs, **kwargs)\n  File \"/usr/lib64/python2.7/subprocess.py\", line 172, in call\n    return Popen(*popenargs, **kwargs).wait()\n  File \"/usr/lib64/python2.7/subprocess.py\", line 394, in __init__\n    errread, errwrite)\n  File \"/usr/lib64/python2.7/subprocess.py\", line 1047, in _execute_child\n    raise child_exception\nOSError: [Errno 2] No such file or directory\nmake: *** [build-AwsLambdaFunctionLambda411132D8] Error 1"}}

Build Failed
2023-03-20 14:56:29,306 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-03-20 14:56:29,321 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-03-20 14:56:29,322 | Unable to find Click Context for getting session_id.
Error: CustomMakeBuilder:MakeBuild - Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

Expected result:

The build to complete successfully

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

{
  "version": "1.76.0",
  "system": {
    "python": "3.8.8",
    "os": "Windows-10-10.0.19041-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "20.10.14",
    "aws_cdk": "Not available",
    "terraform": "1.3.8"
  }
}

Add --debug flag to command you are running

@mcorcoran mcorcoran added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Mar 21, 2023
@moelasmar moelasmar added area/terraform terraform support issue type/feature Feature request and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Mar 21, 2023
@moelasmar
Copy link
Contributor

Hello @mcorcoran,
Thanks for raising this issue. The problem here that for the current version of terraform support, SAM CLI expects that the code exists under the root directory of where the terraform configuration exists.

Could you please move the src, and dist directories to be under the Terraform directory:

Terraform
├── dist
├── main.tf
└── src

and main.tf file content:

provider "aws" {
  region = "us-east-1"
}
provider "archive" {}
data "archive_file" "zip" {
  type        = "zip"
  source_dir  = "./src/"
  output_path = "./dist/index.zip"
}
resource "aws_lambda_function" "lambda" {
  function_name    = "index"
  filename         = data.archive_file.zip.output_path
  source_code_hash = data.archive_file.zip.output_base64sha256
  role             = "ARNROLE"
  handler          = "index.lambda_handler"
  runtime          = "nodejs16.x"
}

resource "null_resource" "sam_metadata_lambda" {
  triggers = {
    resource_name        = "aws_lambda_function.lambda"
    resource_type        = "ZIP_LAMBDA_FUNCTION"
    original_source_code = "./src/index.js"
    built_output_path    = "./dist/index.zip"
  }
  depends_on = [
    aws_lambda_function.lambda,
    data.archive_file.zip
  ]
}

@moelasmar
Copy link
Contributor

we already tracking this issue as a feature request, and the team will work on prioritizing this feature
#4724

@mcorcoran
Copy link
Author

mcorcoran commented Mar 21, 2023

@moelasmar Thanks so much for your reply! I did notice the previous issue but didn't understand it was related all nested folders, not just terraform modules. Unfortunately, un-nesting everything did not fix my issue. I tried moving both \src and \dist' inside the 'terraform` folder, as well as moving main.tf into the root. either way they all failed with the same issues. Below is the log from the current setup

Root
├── dist
├── main.tf
└── src

sam.cmd build --hook-name terraform --beta-features --use-container --build-image DOCKERIMAGE --debug
2023-03-21 17:05:56,806 | Config file location: C:\Project Area\aws-sam-local\samconfig.toml
2023-03-21 17:05:56,806 | Config file 'C:\Project Area\aws-sam-local\samconfig.toml' does not exist
2023-03-21 17:05:56,807 | Looking for internal hook package
2023-03-21 17:05:56,807 | Loaded internal hook package "terraform"
2023-03-21 17:05:56,817 | --beta-features flag is enabled, enabling experimental flag.
2023-03-21 17:05:56,820 |
Experimental features are enabled for this session.
Visit the docs page to learn more about the AWS Beta terms https://aws.amazon.com/service-terms/.

2023-03-21 17:05:56,821 | Running Prepare Hook to prepare the current application
2023-03-21 17:05:56,822 | Executing prepare hook of hook "terraform"
2023-03-21 17:05:56,845 | Normalize the project root directory path C:\Project Area\aws-sam-local
2023-03-21 17:05:56,845 | Normalize the OutputDirPath C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata
2023-03-21 17:05:56,846 | Initializing Terraform application
2023-03-21 17:05:57,042 | 
2023-03-21 17:05:57,043 | Initializing the backend...
2023-03-21 17:05:58,170 | 
2023-03-21 17:05:58,170 | Initializing provider plugins...
2023-03-21 17:05:58,170 | - Reusing previous version of hashicorp/aws from the dependency lock file
2023-03-21 17:05:58,535 | - Reusing previous version of hashicorp/null from the dependency lock file
2023-03-21 17:05:58,691 | - Reusing previous version of hashicorp/archive from the dependency lock file
2023-03-21 17:05:59,726 | - Using previously-installed hashicorp/aws v4.59.0
2023-03-21 17:05:59,763 | - Using previously-installed hashicorp/null v3.2.1
2023-03-21 17:05:59,798 | - Using previously-installed hashicorp/archive v2.3.0
2023-03-21 17:05:59,800 | 
2023-03-21 17:05:59,800 | Terraform has been successfully initialized!
2023-03-21 17:05:59,801 |
2023-03-21 17:05:59,801 | You may now begin working with Terraform. Try running "terraform plan" to see
2023-03-21 17:05:59,801 | any changes that are required for your infrastructure. All Terraform commands
2023-03-21 17:05:59,801 | should now work.
2023-03-21 17:05:59,801 |
2023-03-21 17:05:59,802 | If you ever set or change modules or backend configuration for Terraform,
2023-03-21 17:05:59,802 | rerun this command to reinitialize your working directory. If you forget, other
2023-03-21 17:05:59,802 | commands will detect it and remind you to do so if necessary.

2023-03-21 17:05:59,813 | Creating terraform plan and getting JSON output
2023-03-21 17:06:16,367 | data.archive_file.zip: Reading...
2023-03-21 17:06:16,387 | data.archive_file.zip: Read complete after 0s [id=2095fda074900e136090ee28e10da15f21c376ac]
2023-03-21 17:06:19,832 | 
2023-03-21 17:06:19,833 | Terraform used the selected providers to generate the following execution
2023-03-21 17:06:19,833 | plan. Resource actions are indicated with the following symbols:
2023-03-21 17:06:19,834 | + create
2023-03-21 17:06:19,834 |
2023-03-21 17:06:19,834 | Terraform will perform the following actions:
2023-03-21 17:06:19,834 |
2023-03-21 17:06:19,835 |   # aws_lambda_function.lambda will be created
2023-03-21 17:06:19,835 |   + resource "aws_lambda_function" "lambda" {
2023-03-21 17:06:19,835 | + architectures                  = (known after apply)
2023-03-21 17:06:19,835 | + arn                            = (known after apply)
2023-03-21 17:06:19,835 | + filename                       = "./dist/index.zip"
2023-03-21 17:06:19,836 | + function_name                  = "index"
2023-03-21 17:06:19,836 | + handler                        = "index.lambda_handler"
2023-03-21 17:06:19,836 | + id                             = (known after apply)
2023-03-21 17:06:19,836 | + invoke_arn                     = (known after apply)
2023-03-21 17:06:19,837 | + last_modified                  = (known after apply)
2023-03-21 17:06:19,837 | + memory_size                    = 128
2023-03-21 17:06:19,837 | + package_type                   = "Zip"
2023-03-21 17:06:19,837 | + publish                        = false
2023-03-21 17:06:19,837 | + qualified_arn                  = (known after apply)
2023-03-21 17:06:19,838 | + qualified_invoke_arn           = (known after apply)
2023-03-21 17:06:19,838 | + reserved_concurrent_executions = -1
2023-03-21 17:06:19,838 | + role                           = "ARN"
2023-03-21 17:06:19,838 | + runtime                        = "nodejs16.x"
2023-03-21 17:06:19,839 | + signing_job_arn                = (known after apply)
2023-03-21 17:06:19,839 | + signing_profile_version_arn    = (known after apply)
2023-03-21 17:06:19,840 | + skip_destroy                   = false
2023-03-21 17:06:19,840 | + source_code_hash               = "HASH"

2023-03-21 17:06:19,841 | + source_code_size               = (known after apply)
2023-03-21 17:06:19,842 | + tags_all                       = (known after apply)
2023-03-21 17:06:19,842 | + timeout                        = 3
2023-03-21 17:06:19,843 | + version                        = (known after apply)
2023-03-21 17:06:19,843 |
2023-03-21 17:06:19,844 | + ephemeral_storage {
2023-03-21 17:06:19,844 | + size = (known after apply)
2023-03-21 17:06:19,845 | }
2023-03-21 17:06:19,845 |
2023-03-21 17:06:19,846 | + tracing_config {
2023-03-21 17:06:19,846 | + mode = (known after apply)
2023-03-21 17:06:19,846 | }
2023-03-21 17:06:19,846 | }
2023-03-21 17:06:19,846 |
2023-03-21 17:06:19,847 |   # null_resource.sam_metadata_lambda will be created
2023-03-21 17:06:19,847 |   + resource "null_resource" "sam_metadata_lambda" {
2023-03-21 17:06:19,847 | + id       = (known after apply)
2023-03-21 17:06:19,847 | + triggers = {
2023-03-21 17:06:19,847 | + "built_output_path"    = "./dist/index.zip"
2023-03-21 17:06:19,848 | + "original_source_code" = "./src/index.js"
2023-03-21 17:06:19,848 | + "resource_name"        = "aws_lambda_function.lambda"
2023-03-21 17:06:19,848 | + "resource_type"        = "ZIP_LAMBDA_FUNCTION"
2023-03-21 17:06:19,848 | }
2023-03-21 17:06:19,849 | }
2023-03-21 17:06:19,849 |
2023-03-21 17:06:19,849 | Plan: 2 to add, 0 to change, 0 to destroy.
2023-03-21 17:06:19,849 |
2023-03-21 17:06:19,849 | ─────────────────────────────────────────────────────────────────────────────
2023-03-21 17:06:19,849 |
2023-03-21 17:06:19,850 | Saved the plan to: C:\Users\mjcorcor\AppData\Local\Temp\1\tmpywcmh68u
2023-03-21 17:06:19,850 |
2023-03-21 17:06:19,850 | To perform exactly these actions, run the following command to apply:
2023-03-21 17:06:19,850 | terraform apply "C:\\Users\\mjcorcor\\AppData\\Local\\Temp\\1\\tmpywcmh68u"

2023-03-21 17:06:28,685 | Generating metadata file
2023-03-21 17:06:28,685 | Mapping Lambda functions to their corresponding layers.
2023-03-21 17:06:28,685 | Parsing module:` root
2023-03-21 17:06:28,686 | Parsing module variables
2023-03-21 17:06:28,686 | Parsing module resources
2023-03-21 17:06:28,686 | Parsing module outputs
2023-03-21 17:06:28,687 | Parsing module calls
2023-03-21 17:06:28,687 | Processing resource aws_lambda_function.lambda
2023-03-21 17:06:28,687 | Mapping S3 object sources to corresponding functions
2023-03-21 17:06:28,688 | Linking layers for Lambda function aws_lambda_function.lambda
2023-03-21 17:06:28,688 | Link function configuration aws_lambda_function.lambda layer that has these instances [{'Type': 'AWS::Lambda::Function', 'Properties': {'FunctionName': 'index', 'Code': './dist/index.zip', 
'Handler': 'index.lambda_handler', 'PackageType': 'Zip', 'Runtime': 'nodejs16.x', 'Timeout': 3}, 'Metadata': {'SamResourceId': 'aws_lambda_function.lambda', 'SkipBuild': True}}].
2023-03-21 17:06:28,689 | Resolving resource attribute for resource (aws_lambda_function.lambda) and attribute (layers)
2023-03-21 17:06:28,689 | The value of the attribute layers is None for resource aws_lambda_function.lambda
2023-03-21 17:06:28,689 | The resolved layers for function aws_lambda_function.lambda are []
2023-03-21 17:06:28,690 | Map the resolved layers [] to configuration function aws_lambda_function.lambda.
2023-03-21 17:06:28,690 | There are no layers defined for lambda function aws_lambda_function.lambda
2023-03-21 17:06:28,690 | Enrich the mapped resources with the sam metadata information and generate Makefile
2023-03-21 17:06:28,728 | Check if the input resource name aws_lambda_function.lambda is a postfix to the current module address None
2023-03-21 17:06:28,729 | check if the resource address aws_lambda_function.lambda has a relevant cfn resource or not
2023-03-21 17:06:28,730 | The CFN resource that match the input resource name aws_lambda_function.lambda is AwsLambdaFunctionLambda411132D8
2023-03-21 17:06:28,730 | Enrich the ZIP lambda function AwsLambdaFunctionLambda411132D8 using the metadata properties defined in resource null_resource.sam_metadata_lambda
2023-03-21 17:06:28,731 | Validate if the referenced resource in sam metadata resource null_resource.sam_metadata_lambda is of the expected type ZIP_LAMBDA_FUNCTION
2023-03-21 17:06:28,731 | Extract the source code from the sam metadata resource null_resource.sam_metadata_lambda from property original_source_code
2023-03-21 17:06:28,732 | The found source code value is ./src/index.js and property value is None
2023-03-21 17:06:28,732 | Try to decode the source code value in case if it is a encoded JSON string.
2023-03-21 17:06:28,732 | Source code value could not be parsed as a JSON object. Handle it as normal string value
2023-03-21 17:06:28,732 | The source code path value is ./src/index.js
2023-03-21 17:06:28,732 | The source code path value is not absoulte value. Get the absolute value based on the root directory C:\Project Area\aws-sam-local
2023-03-21 17:06:28,733 | The calculated absolute path of source code is C:\Project Area\aws-sam-local\src\index.js
2023-03-21 17:06:28,733 | Generate Makefile in C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata
2023-03-21 17:06:28,736 | Finished generating metadata file. Storing in C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata\template.json
2023-03-21 17:06:28,738 | Metadata file location - C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata\template.json
2023-03-21 17:06:28,738 | Prepare hook completed and metadata file generated at: C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata\template.json
2023-03-21 17:06:28,742 | Using SAM Template at C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata\template.json
2023-03-21 17:06:28,865 | Using config file: samconfig.toml, config environment: default
2023-03-21 17:06:28,866 | Expand command line arguments to:
2023-03-21 17:06:28,866 | --template_file=C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata\template.json --hook_name=terraform --use_container --build_image=('DOCKERIMAGE',) --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache
2023-03-21 17:06:29,530 | 'build' command is called
2023-03-21 17:06:29,531 | Starting Build inside a container
2023-03-21 17:06:29,531 | No Parameters detected in the template
2023-03-21 17:06:29,563 | Sam customer defined id is more priority than other IDs. Customer defined id for resource AwsLambdaFunctionLambda411132D8 is aws_lambda_function.lambda
2023-03-21 17:06:29,565 | 0 stacks found in the template
2023-03-21 17:06:29,565 | No Parameters detected in the template
2023-03-21 17:06:29,587 | Sam customer defined id is more priority than other IDs. Customer defined id for resource AwsLambdaFunctionLambda411132D8 is aws_lambda_function.lambda
2023-03-21 17:06:29,587 | 1 resources found in the stack
2023-03-21 17:06:29,587 | Found Lambda function with name='AwsLambdaFunctionLambda411132D8' and CodeUri='C:\Project Area\aws-sam-local\src\index.js'
2023-03-21 17:06:29,588 | --base-dir is not presented, adjusting uri C:\Project Area\aws-sam-local\src\index.js relative to C:\Project Area\aws-sam-local\.aws-sam-iacs\iacs_metadata\template.json
2023-03-21 17:06:29,594 | 1 resources found in the stack 
2023-03-21 17:06:29,595 | Found Lambda function with name='AwsLambdaFunctionLambda411132D8' and CodeUri='C:\Project Area\aws-sam-local\src\index.js'
2023-03-21 17:06:29,599 | Instantiating build definitions
2023-03-21 17:06:29,616 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(nodejs16.x, C:\Project Area\aws-sam-local\src\index.js, Zip, , 2e7cf67a-2652-4ec3-b37a-a5a9f3ffb3a9, {'SkipBuild': False, 'BuildMethod': 'makefile', 'ContextPath': 'C:\\Project Area\\aws-sam-local\\.aws-sam-iacs\\iacs_metadata', 'WorkingDirectory': 'C:\\Project Area\\aws-sam-local', 'ProjectRootDirectory': 'C:\\Project Area\\aws-sam-local'}, {}, x86_64, []), Function: Function(function_id='aws_lambda_function.lambda', name='AwsLambdaFunctionLambda411132D8', functionname='index', runtime='nodejs16.x', memory=None, timeout=3, handler='index.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\\Project Area\\aws-sam-local\\src\\index.js', environment=None, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'aws_lambda_function.lambda', 'SkipBuild': False, 'BuildMethod': 'makefile', 'ContextPath': 'C:\\Project Area\\aws-sam-local\\.aws-sam-iacs\\iacs_metadata', 'WorkingDirectory': 'C:\\Project Area\\aws-sam-local', 'ProjectRootDirectory': 'C:\\Project Area\\aws-sam-local'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path='', runtime_management_config=None))   
2023-03-21 17:06:29,621 | Building codeuri: C:\Project Area\aws-sam-local\src\index.js runtime: nodejs16.x metadata: {'SkipBuild': False, 'BuildMethod': 'makefile', 'ContextPath': 'C:\\Project Area\\aws-sam-local\\.aws-sam-iacs\\iacs_metadata', 'WorkingDirectory': 'C:\\Project Area\\aws-sam-local', 'ProjectRootDirectory': 'C:\\Project Area\\aws-sam-local'} architecture: x86_64 functions: aws_lambda_function.lambda
2023-03-21 17:06:29,622 | Building to following folder C:\Project Area\aws-sam-local\.aws-sam\build\AwsLambdaFunctionLambda411132D8

Fetching DOCKERCONTAINER Docker container image......
2023-03-21 17:06:30,821 | Mounting C:\Project Area\aws-sam-local as /tmp/samcli/source:ro,delegated inside runtime container
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Running workflow 'CustomMakeBuilder'
Running CustomMakeBuilder:CopySource
File (.aws-sam) is in ignored set, skipping it
Creating target folders at /tmp/samcli/scratch/.aws-sam-iacs
Copying directory metadata from source (/tmp/samcli/source/.aws-sam-iacs) to destination (/tmp/samcli/scratch/.aws-sam-iacs)
Creating target folders at /tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata
Copying directory metadata from source (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/Makefile) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/Makefile)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/template.json) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/template.json)
Copying source file (/tmp/samcli/source/.aws-sam-iacs/iacs_metadata/z_samcli_backend_override) to destination (/tmp/samcli/scratch/.aws-sam-iacs/iacs_metadata/z_samcli_backend_override)
File (.git) is in ignored set, skipping it
Copying source file (/tmp/samcli/source/.gitignore) to destination (/tmp/samcli/scratch/.gitignore)
Creating target folders at /tmp/samcli/scratch/.terraform
Copying directory metadata from source (/tmp/samcli/source/.terraform) to destination (/tmp/samcli/scratch/.terraform)
Creating target folders at /tmp/samcli/scratch/.terraform/providers
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers) to destination (/tmp/samcli/scratch/.terraform/providers)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64)
Copying source file (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64/terraform-provider-archive_v2.3.0_x5.exe) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/archive/2.3.0/windows_amd64/terraform-provider-archive_v2.3.0_x5.exe)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws)     
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64)
Copying source file (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64/terraform-provider-aws_v4.59.0_x5.exe) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/aws/4.59.0/windows_amd64/terraform-provider-aws_v4.59.0_x5.exe)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null)   
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1)
Creating target folders at /tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64
Copying directory metadata from source (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64)
Copying source file (/tmp/samcli/source/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64/terraform-provider-null_v3.2.1_x5.exe) to destination (/tmp/samcli/scratch/.terraform/providers/registry.terraform.io/hashicorp/null/3.2.1/windows_amd64/terraform-provider-null_v3.2.1_x5.exe)
Copying source file (/tmp/samcli/source/.terraform.lock.hcl) to destination (/tmp/samcli/scratch/.terraform.lock.hcl)
Creating target folders at /tmp/samcli/scratch/.vscode
Copying directory metadata from source (/tmp/samcli/source/.vscode) to destination (/tmp/samcli/scratch/.vscode)
Copying source file (/tmp/samcli/source/.vscode/launch.json) to destination (/tmp/samcli/scratch/.vscode/launch.json)
Copying source file (/tmp/samcli/source/.vscode/settings.json) to destination (/tmp/samcli/scratch/.vscode/settings.json)
Copying source file (/tmp/samcli/source/README.md) to destination (/tmp/samcli/scratch/README.md)
Creating target folders at /tmp/samcli/scratch/dist
Copying directory metadata from source (/tmp/samcli/source/dist) to destination (/tmp/samcli/scratch/dist)
Copying source file (/tmp/samcli/source/dist/index.zip) to destination (/tmp/samcli/scratch/dist/index.zip)
Copying source file (/tmp/samcli/source/main.tf) to destination (/tmp/samcli/scratch/main.tf)
Copying source file (/tmp/samcli/source/package-lock.json) to destination (/tmp/samcli/scratch/package-lock.json)
Copying source file (/tmp/samcli/source/package.json) to destination (/tmp/samcli/scratch/package.json)
Creating target folders at /tmp/samcli/scratch/scripts
Copying directory metadata from source (/tmp/samcli/source/scripts) to destination (/tmp/samcli/scratch/scripts)
Copying source file (/tmp/samcli/source/scripts/sam.sh) to destination (/tmp/samcli/scratch/scripts/sam.sh)
Creating target folders at /tmp/samcli/scratch/src
Copying directory metadata from source (/tmp/samcli/source/src) to destination (/tmp/samcli/scratch/src)
Copying source file (/tmp/samcli/source/src/index.js) to destination (/tmp/samcli/scratch/src/index.js)
CustomMakeBuilder:CopySource succeeded
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /tmp/samcli/artifacts
executing Make: ['make', '--makefile', '/tmp/samcli/manifest/Makefile', 'build-AwsLambdaFunctionLambda411132D8']
python ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py" --expression "|values|root_module|resources|[?address==\"null_resource.sam_metadata_lambda\"]|values|triggers|built_output_path" --directory "/tmp/samcli/artifacts" --target "null_resource.sam_metadata_lambda"
CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 111, in execute
    cwd=self.working_directory,
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/make.py", line 93, in run
    raise MakeExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 301, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 114, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1
Builder workflow failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 111, in execute
    cwd=self.working_directory,
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/make.py", line 93, in run
    raise MakeExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 301, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 114, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/__main__.py", line 133, in main
    experimental_flags=params.get("experimental_flags", []),
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/builder.py", line 164, in build
    return workflow.run()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 95, in wrapper
    func(self, *args, **kwargs)
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 308, in run
    raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: CustomMakeBuilder:MakeBuild - Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1
2023-03-21 17:06:33,771 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "CustomMakeBuilder:MakeBuild - Make Failed: Traceback (most recent call last):\n  File \".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py\", line 329, in <module>\n    subprocess.check_call([\"terraform\", \"init\", \"-reconfigure\", \"-input=false\", \"-force-copy\"])\n  File \"/usr/lib64/python2.7/subprocess.py\", line 185, in check_call\n    retcode = call(*popenargs, **kwargs)\n  File \"/usr/lib64/python2.7/subprocess.py\", line 172, in call\n    return Popen(*popenargs, **kwargs).wait()\n  File \"/usr/lib64/python2.7/subprocess.py\", line 394, in __init__\n    errread, errwrite)\n  File \"/usr/lib64/python2.7/subprocess.py\", line 1047, in _execute_child\n    raise child_exception\nOSError: [Errno 2] No 
such file or directory\nmake: *** [build-AwsLambdaFunctionLambda411132D8] Error 1"}}

Build Failed
2023-03-21 17:06:35,728 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-03-21 17:06:35,741 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-03-21 17:06:35,742 | Unable to find Click Context for getting session_id.
Error: CustomMakeBuilder:MakeBuild - Make Failed: Traceback (most recent call last):
  File ".aws-sam-iacs/iacs_metadata/copy_terraform_built_artifacts.py", line 329, in <module>
    subprocess.check_call(["terraform", "init", "-reconfigure", "-input=false", "-force-copy"])
  File "/usr/lib64/python2.7/subprocess.py", line 185, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
make: *** [build-AwsLambdaFunctionLambda411132D8] Error 1

@moelasmar
Copy link
Contributor

is it possible to push this code to some github repository, so I can have a deeper look ?

@moelasmar
Copy link
Contributor

moelasmar commented Mar 21, 2023

one more thing, does the local-build-nodejs16.x image contain Terraform ? .. could you please share the Dockerfile of this image?

Can you try to execute sam build without the --use-container option ?

@mcorcoran
Copy link
Author

Thank you @moelasmar your questions solved the issue. The container did not in fact have terraform, I'm slapping my head on that one. Thank you for your help!

@github-actions
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
area/terraform terraform support issue type/duplicate type/feature Feature request
Projects
None yet
Development

No branches or pull requests

2 participants