Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS lambda CLI 'update-function-code' does not update lambda_handler file

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"
like image 938
James Wierzba Avatar asked Dec 03 '18 19:12

James Wierzba


People also ask

How do you update Lambda function handler?

Change settings such as the function handler name or Amazon Simple Storage Service (Amazon S3) source bucket – Right-click the function name, and then choose Update Function Code. Complete the Update Code dialog box, and then choose Update.


1 Answers

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.

like image 117
James Wierzba Avatar answered Sep 28 '22 11:09

James Wierzba