Bug: sam local invoke - FileExistsError
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
This issue may be related: https://github.com/aws/aws-sam-cli/issues/3184
### Description:
I am running Java 17 Lambda function locally and I am getting the `[Errno 17] File exists`. As far, as I understand, the problem is caused by license file named `LICENSE`, and a folder named `license` in `META-INF/` folder inside the `.jar` file. `.jar` file system is case-sensitive, and Mac OS FS is case-insensitive, so when SAM tries to unpack files, it cannot create a folder, because file `LICENSE` already exists.
### Steps to reproduce:
Here's my `pom.xml` file.
```xml
4.0.0
com.big-corp
our_amasing_project
1.0-SNAPSHOT
jar
UTF-8
17
17
3.2.1
3.6.1
1.6.0
2.20.17
1.2.0
5.8.1
software.amazon.awssdk
bom
${aws.java.sdk.version}
pom
import
software.amazon.awssdk
s3
software.amazon.awssdk
netty-nio-client
software.amazon.awssdk
apache-client
software.amazon.awssdk
secretsmanager
software.amazon.awssdk
netty-nio-client
software.amazon.awssdk
apache-client
software.amazon.awssdk
url-connection-client
com.amazonaws
aws-lambda-java-core
${aws.lambda.java.version}
com.azure
azure-identity
1.5.0
com.microsoft.graph
microsoft-graph
5.22.0
com.fasterxml.jackson.core
jackson-databind
2.15.2
org.junit.jupiter
junit-jupiter
${junit5.version}
test
org.apache.maven.plugins
maven-compiler-plugin
${maven.compiler.plugin.version}
org.apache.maven.plugins
maven-shade-plugin
${maven.shade.plugin.version}
false
email_to_case_lambdas
*:*
module-info.class
package
shade
```
### Observed result:
```
Error: [Errno 17] File exists: '/var/folders/7k/1jpr7ybs15x1ly785348rjgh0000gp/T/tmp48bohh4f/META-INF/license'
Traceback:
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/decorators.py", line 93, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 184, in wrapped
raise exception # pylint: disable=raising-bad-type
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 149, in wrapped
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/lib/utils/version_checker.py", line 42, in wrapped
actual_result = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/cli/main.py", line 95, in wrapper
return func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/commands/local/invoke/cli.py", line 100, in cli
do_cli(
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/commands/local/invoke/cli.py", line 206, in do_cli
context.local_lambda_runner.invoke(
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/commands/local/lib/local_lambda.py", line 144, in invoke
self.local_runtime.invoke(
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/lib/telemetry/metric.py", line 324, in wrapped_func
return_value = func(*args, **kwargs)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 189, in invoke
container = self.create(function_config, debug_context, container_host, container_host_interface)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 72, in create
code_dir = self._get_code_dir(function_config.code_abs_path)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 290, in _get_code_dir
decompressed_dir: str = _unzip_file(code_path)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/runtime.py", line 524, in _unzip_file
unzip(filepath, temp_dir)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/zip.py", line 92, in unzip
extracted_path = _extract(file_info, output_dir, zip_ref)
File "/opt/homebrew/Cellar/aws-sam-cli/1.90.0/libexec/lib/python3.8/site-packages/samcli/local/lambdafn/zip.py", line 55, in _extract
return zip_ref.extract(file_info, output_dir)
File "/opt/homebrew/Cellar/python@3.8/3.8.17_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/zipfile.py", line 1630, in extract
return self._extract_member(member, path, pwd)
File "/opt/homebrew/Cellar/python@3.8/3.8.17_1/Frameworks/Python.framework/Versions/3.8/lib/python3.8/zipfile.py", line 1697, in _extract_member
os.mkdir(targetpath)
An unexpected error was encountered while executing "sam local invoke".
```
### Expected result:
SAM RUNS
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: Mac OS Ventura 13.4.1
2. `sam --version`: SAM CLI, version 1.90.0
3. AWS region: any
```
sam --info
{
"version": "1.90.0",
"system": {
"python": "3.8.17",
"os": "macOS-13.4.1-arm64-arm-64bit"
},
"additional_dependencies": {
"docker_engine": "24.0.2",
"aws_cdk": "2.80.0 (build bbdb16a)",
"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"
]
}
```
Here's content of META-INF folder inside the jar:
Contributor guide
Assessment
This issue has not been assessed yet.