1
votes

I have a CloudFormation template with a Lambda resource.

In the deploy step, I need to update this Lambda function with my zip file (that I have uploaded via aws cloudformation package). Now, I can pass the name of the Lambda function as a parameter to SAM functionName, but when I do it, it complains that the functionName already exists.

That is fine but how do I specify to just update the code and not try to replace the Lambda function?

1
Just update your existing CF stack with the generated CF template (from aws cloudformation package). There shouldnt be an error... Otherwise please share your CF template.MaiKaY

1 Answers

2
votes

In order to update your Lambda function's code, you just have to follow this process:

# update code artefact and maybe compile it to target folder
# e.g. for Java using Maven: mvn clean compile package

$ aws cloudformation package ...
$ aws cloudformation deploy ...

This will update all resources within your template. See also this how-to guide.

If you only want to update the code of a single Lambda function, you can also use aws lambda update-function-code. However, this can be a bit tedious to do for different Lambda functions in a stack as you need the ARN of each function. Hence, last year I've written a small NPM tool for that called lambda-updater which searches for Lambda functions in a CloudFormation stack and only updates a function's code. It might be of interest for you.