aws-sam-cli
aws-sam-cli copied to clipboard
Bug: sam local invoke - IsADirectoryError
Description:
Not able to run lambda in local on Mac machine in IntellJIDEA
Steps to reproduce:
Ran the follwingg command: sam local invoke LambdaFunction -t template.yml -e event.json --region us-west-2
Observed result:
Invoking com.bhn.csp.accounting.daily.preprocessor.handler.SQSEventHandler::handleRequest (java8)
Decompressing /Users/sshan03/git/csp-accounting-daily-preprocessor/target/csp-accounting-daily-preprocessor-1.0.0.1-SNAPSHOT.jar
Error: [Errno 21] Is a directory: '/var/folders/l6/tn7kt9zx3_xbw0dqg5bxwdrm0000gn/T/tmpafudj9am/LICENSE' Traceback: File "click/core.py", line 1078, in main File "click/core.py", line 1688, in invoke File "click/core.py", line 1688, in invoke File "click/core.py", line 1434, in invoke File "click/core.py", line 783, in invoke File "samcli/cli/cli_config_file.py", line 347, in wrapper File "click/decorators.py", line 92, in new_func File "click/core.py", line 783, in invoke File "samcli/lib/telemetry/metric.py", line 184, in wrapped File "samcli/lib/telemetry/metric.py", line 149, in wrapped File "samcli/lib/utils/version_checker.py", line 42, in wrapped File "samcli/cli/main.py", line 95, in wrapper File "samcli/commands/local/invoke/cli.py", line 103, in cli File "samcli/commands/local/invoke/cli.py", line 201, in do_cli File "samcli/commands/local/lib/local_lambda.py", line 144, in invoke File "samcli/lib/telemetry/metric.py", line 324, in wrapped_func File "samcli/local/lambdafn/runtime.py", line 189, in invoke File "samcli/local/lambdafn/runtime.py", line 72, in create File "samcli/local/lambdafn/runtime.py", line 290, in _get_code_dir File "samcli/local/lambdafn/runtime.py", line 524, in _unzip_file File "samcli/local/lambdafn/zip.py", line 92, in unzip extracted_path = _extract(file_info, output_dir, zip_ref) File "samcli/local/lambdafn/zip.py", line 55, in _extract return zip_ref.extract(file_info, output_dir) File "zipfile.py", line 1630, in extract File "zipfile.py", line 1701, in _extract_member
An unexpected error was encountered while executing "sam local invoke". Search for an existing issue: https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20local%20invoke%20-%20IsADirectoryError Or create a bug report: https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20local%20invoke%20-%20IsADirectoryError
Expected result:
Need to run the Lambda successfully.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: MacBook Pro, 13.6
-
sam --version
: SAM CLI, version 1.101.0 - AWS region: us-west-2
# Paste the output of `sam --info` here
SAM CLI, version 1.101.0
Add --debug flag to command you are running
Hi @sshan03, thanks for opening the issue. Could you provide an example app for us to reproduce and investigate this issue?
I have the same problem.
Steps to reproduce:
- Run
sam init
, choose "Serverless API" and finish the last steps. - Run
sam build
. - Run
sam local invoke
. - Validate the output.
- Repeat step 3.
Observed result:
$ sam local invoke getAllItemsFunction --debug
2023-11-23 23:11:46,157 | Config file location: /Users/enriquemora/Desktop/freelas/scorm/samconfig.toml
2023-11-23 23:11:46,163 | Loading configuration values from [default.['local', 'invoke'].parameters]
(env.command_name.section) in config file at '/Users/enriquemora/Desktop/freelas/scorm/samconfig.toml'...
2023-11-23 23:11:46,164 | Configuration values successfully loaded.
2023-11-23 23:11:46,166 | Configuration values are: {'stack_name': 'scorm'}
2023-11-23 23:11:46,183 | Using SAM Template at
/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/template.yaml
2023-11-23 23:11:46,238 | Using config file: samconfig.toml, config environment: default
2023-11-23 23:11:46,239 | Expand command line arguments to:
2023-11-23 23:11:46,241 | --template_file=/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/template.yaml
--function_logical_id=getAllItemsFunction --no_event --layer_cache_basedir=/Users/enriquemora/.aws-sam/layers-pkg
--container_host=localhost --container_host_interface=127.0.0.1
2023-11-23 23:11:46,243 | local invoke command is called
2023-11-23 23:11:46,260 | No Parameters detected in the template
2023-11-23 23:11:46,301 | Sam customer defined id is more priority than other IDs. Customer defined id for resource
getAllItemsFunction is getAllItemsFunction
2023-11-23 23:11:46,302 | Sam customer defined id is more priority than other IDs. Customer defined id for resource
getByIdFunction is getByIdFunction
2023-11-23 23:11:46,303 | Sam customer defined id is more priority than other IDs. Customer defined id for resource
putItemFunction is putItemFunction
2023-11-23 23:11:46,304 | There is no customer defined id or cdk path defined for resource SampleTable, so we will
use the resource logical id as the resource id
2023-11-23 23:11:46,306 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we
will use the resource logical id as the resource id
2023-11-23 23:11:46,309 | 0 stacks found in the template
2023-11-23 23:11:46,310 | No Parameters detected in the template
2023-11-23 23:11:46,346 | Sam customer defined id is more priority than other IDs. Customer defined id for resource
getAllItemsFunction is getAllItemsFunction
2023-11-23 23:11:46,347 | Sam customer defined id is more priority than other IDs. Customer defined id for resource
getByIdFunction is getByIdFunction
2023-11-23 23:11:46,349 | Sam customer defined id is more priority than other IDs. Customer defined id for resource
putItemFunction is putItemFunction
2023-11-23 23:11:46,350 | There is no customer defined id or cdk path defined for resource SampleTable, so we will
use the resource logical id as the resource id
2023-11-23 23:11:46,352 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we
will use the resource logical id as the resource id
2023-11-23 23:11:46,354 | 5 resources found in the stack
2023-11-23 23:11:46,355 | Found Serverless function with name='getAllItemsFunction' and
CodeUri='getAllItemsFunction'
2023-11-23 23:11:46,357 | --base-dir is not presented, adjusting uri getAllItemsFunction relative to
/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/template.yaml
2023-11-23 23:11:46,358 | Found Serverless function with name='getByIdFunction' and CodeUri='getByIdFunction'
2023-11-23 23:11:46,361 | --base-dir is not presented, adjusting uri getByIdFunction relative to
/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/template.yaml
2023-11-23 23:11:46,365 | Found Serverless function with name='putItemFunction' and CodeUri='putItemFunction'
2023-11-23 23:11:46,366 | --base-dir is not presented, adjusting uri putItemFunction relative to
/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/template.yaml
2023-11-23 23:11:46,401 | Found one Lambda function with name 'getAllItemsFunction'
2023-11-23 23:11:46,403 | Invoking src/handlers/get-all-items.getAllItemsHandler (nodejs20.x)
2023-11-23 23:11:46,405 | Loading AWS credentials from session with profile 'None'
2023-11-23 23:11:46,426 | Resolving code path. Cwd=/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build,
CodeUri=/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/getAllItemsFunction
2023-11-23 23:11:46,428 | Resolved absolute path to code is
/Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/getAllItemsFunction
2023-11-23 23:11:46,430 | Code /Users/enriquemora/Desktop/freelas/scorm/.aws-sam/build/getAllItemsFunction is not a
zip/jar file
2023-11-23 23:11:46,467 | Cleaning all decompressed code dirs
2023-11-23 23:11:46,468 | Telemetry endpoint configured to be
https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-11-23 23:11:46,532 | Telemetry endpoint configured to be
https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-11-23 23:11:46,534 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId':
'd24c4dad-65a8-448c-9ed0-99a9e0add8cb', 'installationId': '5d6f572e-6cdd-4409-80d0-50c64bd54be8', 'sessionId':
'cc6be47f-4f9b-4691-bf6b-f1398e2eee8a', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13',
'samcliVersion': '1.103.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName':
'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName':
'3fc0698a5f3d80f31401cb8c2ad637480682139a3c296665dd691753f35846d6', 'initialCommit': None}, 'duration': 229,
'exitReason': 'TypeError', 'exitCode': 255}}]}
2023-11-23 23:11:46,534 | Unable to find Click Context for getting session_id.
2023-11-23 23:11:46,540 | Sending Telemetry: {'metrics': [{'events': {'requestId':
'6338ca8e-913b-457f-8a26-9dbfc5b09fdd', 'installationId': '5d6f572e-6cdd-4409-80d0-50c64bd54be8', 'sessionId':
'cc6be47f-4f9b-4691-bf6b-f1398e2eee8a', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13',
'samcliVersion': '1.103.0', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'events':
[{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': 'b51eb8d71b5c43aaa2e0c9f83814beba',
'time_stamp': '2023-11-24 02:11:46.157', 'exception_name': None}, {'event_name': 'SamConfigFileExtension',
'event_value': '.toml', 'thread_id': 'd4485a28cef54777960fdfb10384512e', 'time_stamp': '2023-11-24 02:11:46.238',
'exception_name': None}]}}}]}
2023-11-23 23:11:47,184 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com',
port=443): Read timed out. (read timeout=0.1)
2023-11-23 23:11:47,189 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com',
port=443): Read timed out. (read timeout=0.1)
Error: a bytes-like object is required, not 'str'
Traceback:
File "click/core.py", line 1078, in main
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1688, in invoke
File "click/core.py", line 1434, in invoke
File "click/core.py", line 783, in invoke
File "samcli/cli/cli_config_file.py", line 347, in wrapper
File "click/decorators.py", line 92, in new_func
File "click/core.py", line 783, in invoke
File "samcli/lib/telemetry/metric.py", line 184, in wrapped
File "samcli/lib/telemetry/metric.py", line 149, in wrapped
File "samcli/lib/utils/version_checker.py", line 42, in wrapped
File "samcli/cli/main.py", line 95, in wrapper
File "samcli/commands/local/invoke/cli.py", line 103, in cli
File "samcli/commands/local/invoke/cli.py", line 201, in do_cli
File "samcli/commands/local/lib/local_lambda.py", line 144, in invoke
File "samcli/lib/telemetry/metric.py", line 324, in wrapped_func
File "samcli/local/lambdafn/runtime.py", line 189, in invoke
File "samcli/local/lambdafn/runtime.py", line 85, in create
File "samcli/local/docker/lambda_container.py", line 94, in __init__
File "samcli/local/docker/lambda_container.py", line 237, in _get_image
File "samcli/local/docker/lambda_image.py", line 206, in build
File "samcli/local/docker/lambda_image.py", line 480, in _check_base_image_is_current
File "samcli/local/docker/lambda_image.py", line 504, in is_base_image_current
File "samcli/local/docker/lambda_image.py", line 520, in get_remote_image_digest
File "docker/models/images.py", line 356, in get_registry_data
File "docker/utils/decorators.py", line 34, in wrapper
File "docker/utils/decorators.py", line 19, in wrapped
File "docker/api/image.py", line 287, in inspect_distribution
File "docker/api/client.py", line 274, in _result
File "docker/api/client.py", line 270, in _raise_for_status
File "docker/errors.py", line 34, in create_api_error_from_http_exception
File "docker/errors.py", line 34, in <genexpr>
An unexpected error was encountered while executing "sam local invoke".
Search for an existing issue:
https://github.com/aws/aws-sam-cli/issues?q=is%3Aissue+is%3Aopen+Bug%3A%20sam%20local%20invoke%20-%20TypeError
Or create a bug report:
https://github.com/aws/aws-sam-cli/issues/new?template=Bug_report.md&title=Bug%3A%20sam%20local%20invoke%20-%20TypeError
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
{
"version": "1.103.0",
"system": {
"python": "3.8.13",
"os": "macOS-13.4.1-x86_64-i386-64bit"
},
"additional_dependencies": {
"docker_engine": "4.7.2",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}