'sam deploy error when using sam build --use-container
Description: I'm attempting to create a deployment for a package that uses node-canvas. I'm on windows so have to build using sam build --use-container for it to work. If i don't it still builds but i get errors on the stack saying "Invalid ELF Header" I found that's related to windows/linux incompatibilites. So i switched to using the --use-container
Everything builds swimmingly but when i attempt to package or deploy i get an error
Error: Unable to upload artifact ChartJSToImageFunction referenced by CodeUri parameter of ChartJSToImageFunction resource.
[Errno 22] Invalid argument: 'C:\\Users\\brett\\workspace\\chartjstoimage\\.aws-sam\\build\\ChartJSToImageFunction\\node_modules\\.bin\\acorn'
My template file excerpt
ChartJSToImageFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: chartjs-to-image/
Handler: index.lambdaHandler
Runtime: nodejs14.x
#Environment:
#Variables:
Events:
ChartJSApiChart:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref ChartJSToImageApi
Path: /chart
Method: post
Auth:
ApiKeyRequired: true
The node_modules folder all seems correct apart from the .bin folder
I would expect to see the deploy upload something successfully. I have no idea why the node modules folder appears strange
The actual node_modules folder in the js folder looks like this
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
OS: Windows
sam --version: 1.38.1
AWS region: ap-southeast-2
Add --debug flag to command you are running
sam build --use-container --debug
2022-02-22 21:58:58,471 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-02-22 21:58:58,471 | Using config file: samconfig.toml, config environment: default
2022-02-22 21:58:58,471 | Expand command line arguments to:
2022-02-22 21:58:58,471 | --template_file=C:\Users\brett\workspace\chartjstoimage\template.yaml --use_container --skip_pull_image --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache
2022-02-22 21:59:00,456 | 'build' command is called
2022-02-22 21:59:00,456 | Starting Build inside a container
2022-02-22 21:59:00,464 | No Parameters detected in the template
2022-02-22 21:59:00,491 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,491 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,499 | 2 stacks found in the template
2022-02-22 21:59:00,499 | No Parameters detected in the template
2022-02-22 21:59:00,507 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,507 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,507 | 2 resources found in the stack
2022-02-22 21:59:00,507 | No Parameters detected in the template
2022-02-22 21:59:00,523 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,523 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,523 | Found Serverless function with name='ChartJSToImageFunction' and CodeUri='chartjs-to-image/'
2022-02-22 21:59:00,523 | --base-dir is not presented, adjusting uri chartjs-to-image/ relative to C:\Users\brett\workspace\chartjstoimage\template.yaml
2022-02-22 21:59:00,523 | No Parameters detected in the template
2022-02-22 21:59:00,540 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 21:59:00,540 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
2022-02-22 21:59:03,001 | No Parameters detected in the template
2022-02-22 21:59:03,017 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 21:59:03,017 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
2022-02-22 21:59:03,017 | Instantiating build definitions
2022-02-22 21:59:03,017 | Same function build definition found, adding function (Previous: BuildDefinition(nodejs14.x, C:\Users\brett\workspace\chartjstoimage\chartjs-to-image, Zip, , 29630afb-d790-4
b1b-a5d3-56078ffe5c33, {}, {}, x86_64, []), Current: BuildDefinition(nodejs14.x, C:\Users\brett\workspace\chartjstoimage\chartjs-to-image, Zip, , ad4bdf8a-8cc1-4ed4-b561-406fe8d4cab8, {}, {}, x86_64,
[]), Function: Function(function_id='ChartJSToImageFunction', name='ChartJSToImageFunction', functionname='ChartJSToImageFunction', runtime='nodejs14.x', memory=2048, timeout=30, handler='index.lamb
daHandler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:\\Users\\brett\\workspace\\chartjstoimage\\chartjs-to-image', environment=None, rolearn=None, layers=[], events={'ChartJSApi
Chart': {'Type': 'Api', 'Properties': {'RestApiId': 'ChartJSToImageApi', 'Path': '/chart', 'Method': 'post', 'Auth': {'ApiKeyRequired': True}}}}, metadata={'SamResourceId': 'ChartJSToImageFunction'},
inlinecode=None, codesign_config_arn=None, architectures=None, stack_path=''))
2022-02-22 21:59:03,025 | Building codeuri: C:\Users\brett\workspace\chartjstoimage\chartjs-to-image runtime: nodejs14.x metadata: {} architecture: x86_64 functions: ['ChartJSToImageFunction']
2022-02-22 21:59:03,025 | Building to following folder C:\Users\brett\workspace\chartjstoimage\.aws-sam\build\ChartJSToImageFunction
2022-02-22 21:59:03,059 | Requested to skip pulling images ...
2022-02-22 21:59:03,059 | Mounting C:\Users\brett\workspace\chartjstoimage\chartjs-to-image 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 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', 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 'NodejsNpmBuilder' to support capabilities 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Running workflow 'NodejsNpmBuilder'
Running NodejsNpmBuilder:NpmPack
NODEJS packaging file:/tmp/samcli/source to /tmp/samcli/scratch
executing NPM: ['npm', 'pack', '-q', 'file:/tmp/samcli/source']
NODEJS packed to chartjs-to-image-1.5.1.tgz
NODEJS extracting to /tmp/samcli/scratch/unpacked
NodejsNpmBuilder:NpmPack succeeded
Running NodejsNpmBuilder:CopyNpmrc
NodejsNpmBuilder:CopyNpmrc succeeded
Running NodejsNpmBuilder:CopySource
Creating target folders at /tmp/samcli/artifacts
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package) to destination (/tmp/samcli/artifacts)
Copying source file (/tmp/samcli/scratch/unpacked/package/logging.js) to destination (/tmp/samcli/artifacts/logging.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/package.json) to destination (/tmp/samcli/artifacts/package.json)
Copying source file (/tmp/samcli/scratch/unpacked/package/telemetry.js) to destination (/tmp/samcli/artifacts/telemetry.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/LICENSE) to destination (/tmp/samcli/artifacts/LICENSE)
Copying source file (/tmp/samcli/scratch/unpacked/package/README.md) to destination (/tmp/samcli/artifacts/README.md)
Copying source file (/tmp/samcli/scratch/unpacked/package/.dockerignore) to destination (/tmp/samcli/artifacts/.dockerignore)
Copying source file (/tmp/samcli/scratch/unpacked/package/.eslintignore) to destination (/tmp/samcli/artifacts/.eslintignore)
Creating target folders at /tmp/samcli/artifacts/scripts
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package/scripts) to destination (/tmp/samcli/artifacts/scripts)
Copying source file (/tmp/samcli/scratch/unpacked/package/scripts/update_docker.sh) to destination (/tmp/samcli/artifacts/scripts/update_docker.sh)
Copying source file (/tmp/samcli/scratch/unpacked/package/.eslintrc.js) to destination (/tmp/samcli/artifacts/.eslintrc.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/index.js) to destination (/tmp/samcli/artifacts/index.js)
Creating target folders at /tmp/samcli/artifacts/lib
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package/lib) to destination (/tmp/samcli/artifacts/lib)
Copying source file (/tmp/samcli/scratch/unpacked/package/lib/graphviz.js) to destination (/tmp/samcli/artifacts/lib/graphviz.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/lib/pdf.js) to destination (/tmp/samcli/artifacts/lib/pdf.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/lib/qr.js) to destination (/tmp/samcli/artifacts/lib/qr.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/lib/charts.js) to destination (/tmp/samcli/artifacts/lib/charts.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/lib/google_image_charts.js) to destination (/tmp/samcli/artifacts/lib/google_image_charts.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/lib/util.js) to destination (/tmp/samcli/artifacts/lib/util.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/lefthook.yml) to destination (/tmp/samcli/artifacts/lefthook.yml)
Creating target folders at /tmp/samcli/artifacts/test
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package/test) to destination (/tmp/samcli/artifacts/test)
Creating target folders at /tmp/samcli/artifacts/test/monit
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package/test/monit) to destination (/tmp/samcli/artifacts/test/monit)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/monit/quickchart_monit.cfg) to destination (/tmp/samcli/artifacts/test/monit/quickchart_monit.cfg)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/monit/install.sh) to destination (/tmp/samcli/artifacts/test/monit/install.sh)
Creating target folders at /tmp/samcli/artifacts/test/perf
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package/test/perf) to destination (/tmp/samcli/artifacts/test/perf)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/perf/run.sh) to destination (/tmp/samcli/artifacts/test/perf/run.sh)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/perf/basic.yml) to destination (/tmp/samcli/artifacts/test/perf/basic.yml)
Creating target folders at /tmp/samcli/artifacts/test/ci
Copying directory metadata from source (/tmp/samcli/scratch/unpacked/package/test/ci) to destination (/tmp/samcli/artifacts/test/ci)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/color_helpers.js) to destination (/tmp/samcli/artifacts/test/ci/color_helpers.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/graphviz.js) to destination (/tmp/samcli/artifacts/test/ci/graphviz.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/qr_helpers.js) to destination (/tmp/samcli/artifacts/test/ci/qr_helpers.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/chart_helpers.js) to destination (/tmp/samcli/artifacts/test/ci/chart_helpers.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/qr.js) to destination (/tmp/samcli/artifacts/test/ci/qr.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/charts.js) to destination (/tmp/samcli/artifacts/test/ci/charts.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/app.js) to destination (/tmp/samcli/artifacts/test/ci/app.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/test/ci/google_image_charts.js) to destination (/tmp/samcli/artifacts/test/ci/google_image_charts.js)
Copying source file (/tmp/samcli/scratch/unpacked/package/Dockerfile) to destination (/tmp/samcli/artifacts/Dockerfile)
Copying source file (/tmp/samcli/scratch/unpacked/package/.travis.yml) to destination (/tmp/samcli/artifacts/.travis.yml)
NodejsNpmBuilder:CopySource succeeded
Running NodejsNpmBuilder:NpmInstall
NODEJS installing in: /tmp/samcli/artifacts
executing NPM: ['npm', 'install', '-q', '--no-audit', '--no-save', '--production', '--unsafe-perm']
NodejsNpmBuilder:NpmInstall succeeded
Running NodejsNpmBuilder:CleanUpNpmrc
NodejsNpmBuilder:CleanUpNpmrc succeeded
Running NodejsNpmBuilder:LockfileCleanUp
NodejsNpmBuilder:LockfileCleanUp succeeded
2022-02-22 22:00:05,069 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "result": {"artifacts_dir": "/tmp/samcli/artifacts"}}
2022-02-22 22:00:05,077 | Build inside container was successful. Copying artifacts from container to host
2022-02-22 22:00:05,627 | Copying from container: /tmp/samcli/artifacts/. -> C:\Users\brett\workspace\chartjstoimage\.aws-sam\build\ChartJSToImageFunction
2022-02-22 22:00:30,159 | Build inside container succeeded
2022-02-22 22:00:30,159 | No Parameters detected in the template
2022-02-22 22:00:30,183 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 22:00:30,183 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
2022-02-22 22:00:30,183 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 22:00:30,183 | There is no customer defined id or cdk path defined for resource ChartJSToImageFunction, so we will use the resource logical id as the resource id
Build Succeeded
Built Artifacts : .aws-sam\build
Built Template : .aws-sam\build\template.yaml
sam deploy --debug
2022-02-22 22:01:38,095 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-02-22 22:01:38,095 | Using config file: samconfig.toml, config environment: default
2022-02-22 22:01:38,095 | Expand command line arguments to:
2022-02-22 22:01:38,095 | --template_file=C:\Users\brett\workspace\chartjstoimage\.aws-sam\build\template.yaml --fail_on_empty_changeset --confirm_changeset --disable_rollback --stack_name=chartjs-to
-image --s3_bucket=aws-sam-cli-managed-default-samclisourcebucket-1ovvjox337sre --s3_prefix=chartjs-to-image --capabilities=['CAPABILITY_IAM']
2022-02-22 22:01:38,488 | No Parameters detected in the template
2022-02-22 22:01:38,528 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 22:01:38,528 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ChartJSToImageFunction is ChartJSToImageFunction
2022-02-22 22:01:38,528 | 2 stacks found in the template
2022-02-22 22:01:38,624 | There is no customer defined id or cdk path defined for resource ChartJSToImageApi, so we will use the resource logical id as the resource id
2022-02-22 22:01:38,632 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ChartJSToImageFunction is ChartJSToImageFunction
2022-02-22 22:01:38,632 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ChartJSToImageApi is ChartJSToImageApi
2022-02-22 22:01:38,632 | Sam customer defined id is more priority than other IDs. Customer defined id for resource ChartJSToImageFunction is ChartJSToImageFunction
2022-02-22 22:01:38,786 | Unable to export
Traceback (most recent call last):
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\package\packageable_resources.py", line 127, in export
self.do_export(resource_id, resource_dict, parent_dir)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\package\packageable_resources.py", line 149, in do_export
uploaded_url = upload_local_artifacts(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\package\utils.py", line 171, in upload_local_artifacts
return zip_and_upload(local_path, uploader, extension)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\package\utils.py", line 188, in zip_and_upload
with zip_folder(local_path) as (zip_file, md5_hash):
File "contextlib.py", line 113, in __enter__
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\package\utils.py", line 210, in zip_folder
md5hash = dir_checksum(folder_path, followlinks=True)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\hash.py", line 81, in dir_checksum
filepath_checksum = file_checksum(file)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\lib\utils\hash.py", line 28, in file_checksum
with open(file_name, "rb") as file_handle:
OSError: [Errno 22] Invalid argument: 'C:\\Users\\brett\\workspace\\chartjstoimage\\.aws-sam\\build\\ChartJSToImageFunction\\node_modules\\.bin\\acorn'
2022-02-22 22:01:38,794 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'acffb251-072d-4453-9933-279d5a54b61f', 'installationId': '59f31714-517c-44fc-9e09-f6967b1106ed', 'sessionId': '
fb974c7a-376a-4075-89a2-e613863f8750', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.38.1', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '
ap-southeast-2', 'commandName': 'sam deploy', 'metricSpecificAttributes': {'projectType': 'CFN'}, 'duration': 697, 'exitReason': 'ExportFailedError', 'exitCode': 1}}]}
2022-02-22 22:01:39,506 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: Unable to upload artifact ChartJSToImageFunction referenced by CodeUri parameter of ChartJSToImageFunction resource.
[Errno 22] Invalid argument: 'C:\\Users\\brett\\workspace\\chartjstoimage\\.aws-sam\\build\\ChartJSToImageFunction\\node_modules\\.bin\\acorn'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


