SAM CLI should support CodeUri.Bucket for existing lambda functions
SAM CLI should support CodeUri.Bucket for existing lambda functions.
In my company we have some lambda functions that we used to share in CF stacks (e.g. a function to requeue messages from a dead letter queue to the original queue ).
When I try to define a function in my stack with a CodeUri that refers to an existing bucket I get this warning from sam build:
Lambda function 'TaskExecutionRequeueFunction' has specified S3 location for CodeUri which is unsupported. Using default value of '.' instead and the whole project directory is build an uploaded.
my sam cli version is currently 1.11.0
I'd like to have the ability to use these external functions also in my SAM stacks.
Proposal
This should be possible:
RequeueFunction:
Type: AWS::Serverless::Function
Properties:
Timeout: 120
Handler: requeue.handler
CodeUri:
Bucket: !Ref 'LambdaFunctionsBucket'
Key: 'sqs/requeue.zip'
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt Queue.QueueName
- SQSPollerPolicy:
QueueName: !GetAtt DeadletterQueue.QueueName
Environment:
Variables:
DEAD_LETTER_QUEUE_URL: !Ref DeadletterQueue
ACTIVE_QUEUE_URL: !Ref Queue
Runtime: python3.8
Things to consider:
- Will this require any updates to the SAM Spec?
No. This is already defined behaviour and SAM CLI should implement it
Yes, that's definitely not optimal. If all of your functions are defined this way you should be able to package and deploy no problem without running build, but if you're mixing and matching it will be more difficult.
Researching the safest way to change this behavior.
I spent hours breaking my head on it thinking my old working code stopped working!! Facing the same issue.
To clarify in case some templates have only S3 CodeUris, if you don't have any local CodeUri references you do not need to run sam build at all and can directly deploy - you likely don't even need to run sam package. Where this becomes tricky is when you have a mix of both.
Update: latest SAM CLI does not build or package functions with S3 CordeUri anymore