Shell script to update Lambda function

After you’ve updated the code for your Lambda function, here’s a shell script to update the Lambda package and redeploy it to AWS. AWS’s official documentation on aws lambda update-function-code is here. There are much better ways to structure and manage your Lambda functions, but, in case you’re rolling old school, this shell script is handy. Also, I’ve included below the tree view of a basic directory structure for a Lambda function that this script would serve.

update_function.sh
1
2
3
4
5
6
7
8
9
10
#!/bin/zsh
lambda_name="LambdaName"
zip_file="${lambda_name}.zip"

files="lambda_function.py"
chmod -R 755 ${files}
zip -r "${zip_file}" $files

aws lambda update-function-code --region "us-east-1" --function-name "${lambda_name}" --zip-file "fileb://${zip_file}"

1
2
3
4
5
6
7
8
9
10
/psycopg2/
/test_function.sh
/dist
/dist/lambda_function.py
/deployment_bundle.zip
/event.json
/output.json
/lambda_function.py
/create_function.sh
/update_function.sh