i like to do it like this:
clear && zip -r function.zip . -x "*.git*" -x ".env" -x "event.json" -x "function.zip" > /dev/null && aws lambda update-function-code --function-name YOUR_FUNCTION_NAME --zip-file fileb://function.zip > /dev/null && rm function.zip
Command Explanation
clear
Clears the terminal screen.
zip -r function.zip . -x "*.git*" -x ".env" -x "event.json" -x "function.zip"
This command creates a zip archive (function.zip) of the current directory (.) while recursively including all files and subdirectories, but excluding:
- Files and directories matching
*.git* (usually Git repository metadata and history).
- The
.env file (commonly used for environment variables).
- The
event.json file (often used for testing events in AWS Lambda).
- The
function.zip file itself to avoid including the zip archive being created in the archive.
The > /dev/null part suppresses the output of the zip command, sending it to the null device, effectively hiding it from the terminal.
aws lambda update-function-code --function-name YOUR_FUNCTION_NAME --zip-file fileb://function.zip
This command updates the AWS Lambda function code.
--function-name YOUR_FUNCTION_NAME: Specifies the name of the Lambda function to update. Replace YOUR_FUNCTION_NAME with the actual name of your Lambda function.
--zip-file fileb://function.zip: Points to the zip file (function.zip) containing the updated function code to upload.
Again, > /dev/null suppresses the output of this command.
rm function.zip
Deletes the function.zip file after the Lambda function code has been updated.