Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda update_function_code not incrementing Version when Publish=True #8337

Open
ekolve opened this issue Nov 19, 2024 · 3 comments
Open

Lambda update_function_code not incrementing Version when Publish=True #8337

ekolve opened this issue Nov 19, 2024 · 3 comments
Labels
debugging Working with user to figure out if there is an issue

Comments

@ekolve
Copy link

ekolve commented Nov 19, 2024

When running the following beneath moto

import boto3
client = boto3.client('lambda', region_name='us-east-2')
res = client.update_function_code(FunctionName='test-function', ZipFile=<somearchive>, Publish=True)
print(res["Version"])

After the first invocation this prints out 1, but this also prints out 1 for both results if the following is run:

import boto3
client = boto3.client('lambda', region_name='us-east-2')
res = client.update_function_code(FunctionName='test-function', ZipFile=<somearchive>, Publish=True)
print(res["Version"])
res = client.update_function_code(FunctionName='test-function', ZipFile=<somearchive>, Publish=True)
print(res["Version"])

I would expect the second invocation to print out 2 since a new version is getting published.

@ekolve ekolve changed the title Lambda update_function_code not increment Version when Publish=True Lambda update_function_code not incrementing Version when Publish=True Nov 19, 2024
@ekolve
Copy link
Author

ekolve commented Nov 19, 2024

I tracked down the issue to this:

if latest_published.code_sha_256 == function.code_sha_256:

            if latest_published.code_sha_256 == function.code_sha_256:
                # Nothing has changed, don't publish
                return latest_published

AWS doesn't apply the same logic on their side when code is published. They seem to publish a new version even if the code hasn't changed.

@bblommers
Copy link
Collaborator

According to the documentation, AWS does not publish a new version when calling publish_version with the same code.
From https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html:

Lambda publishes a new function version only if the code has never been published, or if the code has changed from the last published version. If there is no change, the function version remains at the last published version.

Does the update_function_code behave differently? If so, that would be.. confusing.

@bblommers bblommers added the debugging Working with user to figure out if there is an issue label Nov 20, 2024
@ekolve
Copy link
Author

ekolve commented Nov 21, 2024

Here is what I am observing with AWS:

import boto3
client = boto3.client('lambda', region_name='us-west-2')
res = client.update_function_code(FunctionName='test-handler', ZipFile=<archive>, Publish=True)
print(res["Version"]) # prints 1
res = client.update_function_code(FunctionName='test-handler', ZipFile=<archive>, Publish=True) # archive is identical to the first call
print(res["Version"]) # prints 2
res = client.publish_version(FunctionName='test-handler')
print(res["Version"]) # prints 2

So the docs for publish_version are correct, the docs for update_function_code https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/update_function_code.html
state the following:

Publish (boolean) – Set to true to publish a new version of the function after updating the code. 
This has the same effect as calling PublishVersion separately.

Given all this, I'm not sure what the right course of action is with respect to mocking. Their docs are ambiguous and I can modify my test to slightly modify my archive to trigger the version to get updated with moto, but it would be nice if AWS would state explicitly what should happen for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debugging Working with user to figure out if there is an issue
Projects
None yet
Development

No branches or pull requests

2 participants