Reputation: 136197
Currently, when I update my Lambda function, I
aws s3 cp [local] [bucket]
Is there a way to do all of this via command line?
Upvotes: 3
Views: 5440
Reputation: 454
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
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:
*.git*
(usually Git repository metadata and history)..env
file (commonly used for environment variables).event.json
file (often used for testing events in AWS Lambda).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.
Upvotes: 1
Reputation: 136197
$ aws lambda update-function-code \
--function-name your-lambda-name \
--s3-bucket your-bucket \
--s3-key your-key
See update-function-code of the aws
command line program.
Upvotes: 7