aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

SAM CLI should support CodeUri.Bucket for existing lambda functions

Open superwese opened this issue 5 years ago • 4 comments

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:

  1. Will this require any updates to the SAM Spec?

No. This is already defined behaviour and SAM CLI should implement it

superwese avatar Jan 06 '21 16:01 superwese

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.

awood45 avatar Jan 08 '21 00:01 awood45

I spent hours breaking my head on it thinking my old working code stopped working!! Facing the same issue.

mj-roychowdhury avatar Jan 11 '21 18:01 mj-roychowdhury

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.

awood45 avatar Jan 11 '21 20:01 awood45

Update: latest SAM CLI does not build or package functions with S3 CordeUri anymore

aahung avatar May 03 '21 20:05 aahung