aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.52k stars 1.17k forks source link

No such file or directory error for sam build #1278

Closed jjbuck closed 5 years ago

jjbuck commented 5 years ago

Description

Running sam build yields a "No such file or directory" error.

Steps to reproduce

Create new AWS serverless project from IntelliJ, and either a) deploy from IntelliJ or b) run the sam build command directly at the cli. This is essentially just following the example shown in https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/.

/usr/local/bin/sam build --template /Users/<user>/code/GetImageSize/template.yaml --build-dir /Users/<user>/code/GetImageSize/.aws-sam/build

Observed result

2019-07-17 08:48:15 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-07-17 08:48:15 Changing event name from before-call.apigateway to before-call.api-gateway
2019-07-17 08:48:15 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-07-17 08:48:15 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-07-17 08:48:15 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-07-17 08:48:15 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-07-17 08:48:15 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-07-17 08:48:15 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-07-17 08:48:15 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-07-17 08:48:15 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-07-17 08:48:15 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-07-17 08:48:15 Changing event name from creating-client-class.iot-data to creating-client-class.iot-data-plane
2019-07-17 08:48:15 Changing event name from before-call.apigateway to before-call.api-gateway
2019-07-17 08:48:15 Changing event name from request-created.machinelearning.Predict to request-created.machine-learning.Predict
2019-07-17 08:48:15 Changing event name from before-parameter-build.autoscaling.CreateLaunchConfiguration to before-parameter-build.auto-scaling.CreateLaunchConfiguration
2019-07-17 08:48:15 Changing event name from before-parameter-build.route53 to before-parameter-build.route-53
2019-07-17 08:48:15 Changing event name from request-created.cloudsearchdomain.Search to request-created.cloudsearch-domain.Search
2019-07-17 08:48:15 Changing event name from docs.*.autoscaling.CreateLaunchConfiguration.complete-section to docs.*.auto-scaling.CreateLaunchConfiguration.complete-section
2019-07-17 08:48:15 Changing event name from before-parameter-build.logs.CreateExportTask to before-parameter-build.cloudwatch-logs.CreateExportTask
2019-07-17 08:48:15 Changing event name from docs.*.logs.CreateExportTask.complete-section to docs.*.cloudwatch-logs.CreateExportTask.complete-section
2019-07-17 08:48:15 Changing event name from before-parameter-build.cloudsearchdomain.Search to before-parameter-build.cloudsearch-domain.Search
2019-07-17 08:48:15 Changing event name from docs.*.cloudsearchdomain.Search.complete-section to docs.*.cloudsearch-domain.Search.complete-section
2019-07-17 08:48:15 'build' command is called
2019-07-17 08:48:15 No Parameters detected in the template
2019-07-17 08:48:15 2 resources found in the template
2019-07-17 08:48:15 Found Serverless function with name='HelloWorldFunction' and CodeUri='target/HelloWorld-1.0.jar'
2019-07-17 08:48:15 Building resource 'HelloWorldFunction'
2019-07-17 08:48:15 Looking for a supported build workflow in following directories: ['/Users/<user>/code/GetImageSize/target/HelloWorld-1.0.jar', '/Users/<user>/code/GetImageSize']
2019-07-17 08:48:15 Loading workflow module 'aws_lambda_builders.workflows'
2019-07-17 08:48:15 Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2019-07-17 08:48:15 Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2019-07-17 08:48:15 Found workflow 'JavaMavenWorkflow' to support capabilities 'Capability(language='java', dependency_manager='maven', application_framework=None)'
2019-07-17 08:48:15 Running workflow 'JavaMavenWorkflow'
2019-07-17 08:48:15 Running JavaMavenWorkflow:CopySource
2019-07-17 08:48:15 JavaMavenWorkflow:CopySource raised unhandled exception
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/0.18.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 248, in run
    action.execute()
  File "/usr/local/Cellar/aws-sam-cli/0.18.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/actions.py", line 101, in execute
    copytree(self.source_dir, self.dest_dir, ignore=shutil.ignore_patterns(*self.excludes))
  File "/usr/local/Cellar/aws-sam-cli/0.18.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/utils.py", line 43, in copytree
    names = os.listdir(source)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/<user>/code/GetImageSize/target/HelloWorld-1.0.jar'
Error: JavaMavenWorkflow:CopySource - [Errno 2] No such file or directory: '/Users/<user>/code/GetImageSize/target/HelloWorld-1.0.jar'

Expected result

Expected sam build to create an artifact for Lambda without error.

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

  1. OS: MacOS 10.12.6
  2. sam --version: SAM CLI, version 0.18.0
jfuss commented 5 years ago

@jjbuck It looks like your CodeUri is a jar? It should be the directory of your source not the compiled artifact.

jfuss commented 5 years ago

Closing due to no response. Feel free to re-open.

ericljiang commented 4 years ago

@jjbuck It looks like your CodeUri is a jar? It should be the directory of your source not the compiled artifact.

It's very easy to miss this in the docs. It makes me wonder if it's correct for CodeUri to be reused for two slightly different meanings. A downside is that I can't use the same sam template for multiple build methods. If I want to build with sam, I need to reference the source files; if I want to build outside of sam, I need to change my template to reference the compiled artifact.