Lambda function updating cannot be made atomic with RevisionId

0

A number of Lambda API calls allow for a RevisionId argument to ensure that the operation only continues if the current revision of the Lambda function matches, very similar to an atomic Compare-And-Swap operation. However, this RevisionId appears to be useless for performing some atomic operations, for the following reason:

Suppose I want to update a function's code and then publish it, in 2 separate steps (I know it can be done in 1 step, but this does not interest me, because I cannot set the description of a published version in 1 update/publish step...it must be done in 2 steps). The update_function_code call returns a RevisionId that corresponds to the "in progress" update of the function. This RevisionId cannot be used because it will change once the function becomes active/updated. This new RevisionId can only be obtained by get_function.

Update code -> RevisionId A (in progress) -> RevisionId B (updated/active) -> Get Function -> RevisionId B -> Publish Function

There exists a race condition due to the fact that I must call get_function in order to get the current RevisionId before I continue with publishing my function. This race condition makes it impossible create an atomic sequence of operations that includes a update_function_code operation, because the RevisionId that it returns cannot be relied on, and has to be refreshed with a get_function call. Concurrently, another operation could change the RevisionId, and you wouldn't know, because you're depending on get_function to return an unknown RevisionId.

amoffat
asked 2 years ago515 views
1 Answer
0
Accepted Answer

The solution that I came up with is to sometimes use RevisionId and to sometimes use CodeSha256. Up until the call to update_function_code, you can use RevisionId, then when you call update_function_code, it returns a response containing both a RevisionId and a CodeSha256. The CodeSha256 is static and can be fed into publish_function as a constraint, in the same way as you would use RevisionId.

amoffat
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions