'UpdateFunctionCode in lambda does not update the code

I have followed this blog to update the code of a lambda function using a jar file stored in a S3 bucket. the execution was succeded, but it is not updating the code of target lambda function

Code snippet

console.log('Loading function');
var AWS = require('aws-sdk');
var lambda = new AWS.Lambda();
exports.handler = function(event, context) {

        var functionName = "runJarFile";
        var bucket = "jarfiletest2";
        var key = "lambda-java-example-0.0.1-SNAPSHOT.jar.zip";

        console.log("uploaded to lambda function: " + functionName);
        var params = {
            FunctionName: functionName,
            S3Key: key,
            S3Bucket: bucket,
            Publish: true
        };
        lambda.updateFunctionCode(params, function(err, data) {
            if (err) {
                console.log(err, err.stack);
                context.fail(err);
            } else {
                console.log(data);
                context.succeed(data);
            }
        });
};

Response Thanks in advance



Solution 1:[1]

It's difficult to comment on this without knowing the details about the destination function. What's the output of the GetFunction API call of that Lambda, before and after calling the UpdateFunctionConfig call?

I am interested to see the SHA-256 hash of the code, and the last modified timestamp off that API call before and after calling UpdateFunctionConfig:

{
...
    "CodeSha256": "5tT2qgzYUHoqwR616pZ2dpkn/0J1FrzJmlKidWaaCgk=",
    "LastModified": "2019-09-24T18:20:35.054+0000"
...
}

If the values are exactly the same, can you add this check as per the blog post to see if the bucket and the object exists?

if (bucket == "YOUR_BUCKET_NAME" && key == "YOUR_CODE.zip" && version) {
// your code
} else {
  context.succeed("skipping zip " + key + " in bucket " + bucket + " with version " + version);
}

Solution 2:[2]

Pls try to remove 'Publish: true' to call the latest version not the specified version

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shreyas Gaonkar
Solution 2 James Lee