Open ashleyfrieze opened 4 years ago
Can you give an example of a situation that would trigger this condition?
Closing as there is no response. Feel free to reopen if there is further information or issue.
@CoshUS and @awood45 - sorry for not replying sooner.
Our use case:
.zip
file containing the released artifacts - say target/assembly.zip
sam local start-api
against the template.yaml
to perform testingtarget/assembly.zip
doesn't current exist - maybe we forgot to build, or didn't notice that the .zip
that's output is something like assembly_1.0.0.zip
- the usual sort of stuff that happensThe output of sam on start-api
is normal.
The output of sam while it starts the child container, unzipping the non existent zip into its temp directory before mounting it into the running container, all looks normal.
The error we get is from the lambda runtime saying that the handler cannot be found.
However, the real error is that there's nothing to mount from the CodeUri
.
While it's possible to work out what's gone wrong, an error or warning that there's nothing present behind the location specified in the CodeUri
would be remarkably helpful!
@CoshUS _ don't have the user rights to reopen this
This looks to be a sane ask, marking this as open for contributors.
I would really like to start contributing to this project so I've been looking at a few issues with the contributors/welcome
and contributors/good-first-issue
tags and found this one. It seems pretty straightforward. I've made sure this issue is still reproducible with the latest code as documented below.
I'm using the Hello World Python function which is defined in the template as (Note that CodeUri
references a directory):
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: HelloWorldFunction
Handler: app.lambda_handler
Runtime: python3.8
Architectures:
- x86_64
When I run sam build
and then sam local invoke HelloWorldFunction --debug
, the function executes as expected and I can see this in the logs:
2023-05-26 15:31:24,190 | Invoking app.lambda_handler (python3.8)
2023-05-26 15:31:26,255 | Resolving code path. Cwd=/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build,
CodeUri=/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 15:31:26,256 | Resolved absolute path to code is /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 15:31:26,259 | Decompressing /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 15:31:49,579 | Mounting /private/var/folders/nf/93d01hl9725g48vb7pbt4dr8ns4dm0/T/tmphzxneft1 as /var/task:ro,delegated, inside runtime container
If I change the CodeUri
to point to an existing ZIP file like so:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: HelloWorldFunction/Archive.zip
Handler: app.lambda_handler
Runtime: python3.8
Architectures:
- x86_64
The function executes as expected and I see these logs:
2023-05-26 15:31:24,190 | Invoking app.lambda_handler (python3.8)
2023-05-26 15:31:26,255 | Resolving code path. Cwd=/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build,
CodeUri=/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 15:31:26,256 | Resolved absolute path to code is /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 15:31:26,259 | Decompressing /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 15:31:49,579 | Mounting /private/var/folders/nf/93d01hl9725g48vb7pbt4dr8ns4dm0/T/tmphzxneft1 as /var/task:ro,delegated, inside runtime container
Now if I leave the function pointing to a zip archive but I delete the archive, the function fails with this error message:
Error: 500 Server Error: Internal Server Error ("error while creating mount source path '/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip': chown /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip: permission denied")
And I can see this in the logs (Similar to if I were pointing to a directory but the URI referenced doesn't exist as a file or as a directory):
2023-05-26 13:20:43,606 | Invoking app.lambda_handler (python3.8)
2023-05-26 13:20:45,651 | Resolving code path. Cwd=/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build,
CodeUri=/Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 13:20:45,654 | Resolved absolute path to code is /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip
2023-05-26 13:20:45,655 | Code /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip is not a zip/jar file
2023-05-26 13:21:09,514 | Mounting /Users/dewald.dejager/Documents/sam-cli-reproduce-issue-1754/.aws-sam/build/HelloWorldFunction/Archive.zip as /var/task:ro,delegated, inside runtime container
The comments in the code document the scenarios that are should be catered for: https://github.com/aws/aws-sam-cli/blob/de9da32eeb4300074d9357649bdf8fb1bcbe491f/samcli/local/lambdafn/runtime.py#L271-L275 And this is the implementation of the logic: https://github.com/aws/aws-sam-cli/blob/de9da32eeb4300074d9357649bdf8fb1bcbe491f/samcli/local/lambdafn/runtime.py#L289-L295 I found this test that's a little misleading because the name implies that the file should exist: https://github.com/aws/aws-sam-cli/blob/de9da32eeb4300074d9357649bdf8fb1bcbe491f/tests/unit/local/lambdafn/test_runtime.py#L562-L572 The only other test is for when it is a valid ZIP/JAR file and needs to be decompressed.
This issue suggests that a warning should be logged but I'd like to understand if either of these two are valid use cases?
CodeUri
points to a file that is not a ZIP/JAR file such as foo.exe
in the exampleCodeUri
points to something that does not exist (file/directory)I think the execution should fail and output an error in (1) and potentially in (2) but I'm not sure if there is maybe a valid scenario I'm not considering. Thoughts?
Describe your idea/feature/enhancement
When using
sam local start-lambda
,invoke
orstart-api
, the output describes the activities between the local machine and the lambci container while processing the invocation. When the package is present and a zip/jar, then we even see it being de-compressed before mounting.However, I've been caught out a few times by sam quietly just mounting the
CodeUri
path in the target container when that path does not exist on the local machine. This results in an error which is secondary to the problem.Proposal
While detecting if the
CodeUri
represents something to unzip/unpack, output a warning if theCodeUri
appears to refer to a non-existent path. This will speed up discovery of this common error.Additional Details