6

update-function-code AWS CLI command updates all code files except the handler function file, lambda_function.py

Specifically, I made a bash script that

  1. Downloads code zip from one lambda (source)
  2. Uploads code zip to another lambda (dest)

Everything works, except the main function file lambda_function.py does not get updated.

Oddly, when I download the zip from a lambda, make a change, and then upload to the same lambda, it works (all files are updated).

FYI, here is my bash script to download code from one lambda, and upload to another:

#!/bin/sh

SRC_LAMBDA_FUNCTION_NAME="$1"
DEST_LAMBDA_FUNCTION_NAME="$2"

export PYTHONIOENCODING=utf8

# get lambda function config
LAMBDA_JSON=$(aws lambda get-function --function-name $SRC_LAMBDA_FUNCTION_NAME)
export LAMBDA_JSON

# parse the code zip file download URL (link expires 10 minutes after creation)
ZIP_FILE_URL=$(python -c 'import json,sys,os;obj=json.loads(os.environ["LAMBDA_JSON"]);print(obj["Code"]["Location"])')

# make temp dir
mkdir -p download

# download the code from src lambda
curl -o "download/$SRC_LAMBDA_FUNCTION_NAME.zip" $ZIP_FILE_URL

# upload the code to dest lambda
aws lambda update-function-code --function-name $DEST_LAMBDA_FUNCTION_NAME --zip-file "fileb://download/$SRC_LAMBDA_FUNCTION_NAME.zip"
2
  • I suspect you may be misdiagnosing the issue... update-function-code replaces the entire zip file with a new one and returns the CodeSha256 of the new package. Partial changes should be impossible. Commented Dec 3, 2018 at 23:59
  • @Michael-sqlbot Agreed, and I just found the issue, see my answer .. Commented Dec 4, 2018 at 0:15

2 Answers 2

12

I was verifying the code changes by navigating to the lambda code editor on the AWS web portal, and it appears this was just a client side issue in the web UI.

It took about 5 minutes before the lambda_function.py was updated in the UI (despite refreshing), whereas the other code files did get updated immediately.

It is very strange that other files got updated, but not lambda_function.py. This makes me think it is not just a browser caching issue, but maybe a bug.

Sign up to request clarification or add additional context in comments.

4 Comments

I faced the same issue today. I did not see the updated code in spite of refreshing for about half an hour. Although the aws cli update-function-code reports a success with a new CodeSha256 version. Not sure whether it is a web UI issue or a recent bug introduced!
Update: I was unable to reproduce the issue! So was not able to identify the root cause.
In our case, the code never updated, even after waiting hours. I was running aws lambda update-function-code multiple times and it kept "working" but it was using old code, not the code specified in the zip file. Only after i manually updated the lambda code in the AWS console did subsequent aws cli updates actually succeed.
@sjwoodr yeah, I've experienced that issue. frustrating
2

I believe you may need to publish the new code changes according to https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html

--publish | --no-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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.