3

Currently, when I update my Lambda function, I

  1. Open https://console.aws.amazon.com/lambda/ in a browser and navigate to the lambda function
  2. Choose 'Code entry type: Upload a file from Amazon S3'
  3. Enter the S3 URL I got before from uploading it via command line aws s3 cp [local] [bucket]

Is there a way to do all of this via command line?

0

2 Answers 2

7
$ 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.

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

1 Comment

i think if we are pointing towards s3 bucket no need to use --zip-file
2

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.

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.