sam build doesn't support file as CodeUri
chizou opened this issue · 5 comments
Description:
sam package
allows specifying individual files for the CodeUri
, like so:
TokenVerifier:
Type: AWS::Serverless::Function
Properties:
CodeUri: token_verify.py
Handler: token_verify.lambda_handler
Runtime: python3.7
Timeout: 60
However, if I try to run sam build
on it, I get the following error:
Build Failed
Error: PythonPipBuilder:CopySource - [Errno 20] Not a directory: '/home/github/app/token_verify.py'
Steps to reproduce:
run sam build
Observed result:
I receive the error described above
Expected result:
sam build completes
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: WSLv2
sam --version
: SAM CLI, version 1.40.1- AWS region: us-east-1
Thanks for reporting the issue, we will be investigating it further. Please watch this channel for more updates, and feel free to reach out.
@chizou Can you help us understand your use case?
In the example you provided, I don't think you need to run sam build
.
@hawflau I need sam build
to download the packages from requirements.txt
. I just provided a tiny snippet of the template which is much bigger. The requirements.txt
is required in other parts of the app.
But regardless, shouldn't sam package
and sam build
have the same behavior for CodeUri
?
I'm not sure if its intended behavior for sam package
to be able to refer to an individual file, That's something that needs to be checked.
However sam build
relies on aws-lambda-builders
to be the authoritative source to build across all of lambda support runtimes and requires CodeUri to be a directory so that its a common workflow across languages.
In your case if you do have requirements.txt
this means you have external dependencies that you are importing within your handler, so it will require for your CodeUri to be a directory as well. If your code has zero dependencies, I believe there is an InlineCode
solution that would also work by inling your code directly within the template, but I recommend having a tangible artifact for code.
Closing this issue. Please re-open if this becomes relevant again.