You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过命令行全程完成AWS Lambda代码更新操作?

Can I complete the entire Lambda function update process via command line?

Absolutely! You can fully replace that browser-based workflow with the AWS CLI — it’s even more efficient once you get the hang of it. Here’s a step-by-step breakdown of how to do every part from your terminal:

Prerequisites

First, make sure you’ve installed and configured the AWS CLI with permissions to access both S3 and Lambda (specifically s3:PutObject and lambda:UpdateFunctionCode).

Step 1: Upload your local package to S3

Use the aws s3 cp command to upload your Lambda deployment package (usually a .zip file) to your target S3 bucket:

aws s3 cp ./your-lambda-package.zip s3://your-target-bucket/lambda-packages/your-lambda-package.zip

Replace ./your-lambda-package.zip with the path to your local file, your-target-bucket with your S3 bucket name, and lambda-packages/your-lambda-package.zip with the desired path inside the bucket.

Step 2: Update the Lambda function directly from S3

Instead of navigating to the console and pasting an S3 URL, use the aws lambda update-function-code command to point Lambda directly to your S3 package. This skips the console entirely:

aws lambda update-function-code \
  --function-name YourLambdaFunctionNameOrARN \
  --s3-bucket your-target-bucket \
  --s3-key lambda-packages/your-lambda-package.zip
  • --function-name: Use either your Lambda function’s name or its full ARN.
  • --s3-bucket: The name of the S3 bucket where you uploaded your package.
  • --s3-key: The exact path (key) to your package within the bucket (matches what you used in the s3 cp command).

Optional: Publish a new version

If you want to immediately create a new published version of your function (instead of just updating the $LATEST version), add the --publish flag:

aws lambda update-function-code \
  --function-name YourLambdaFunctionNameOrARN \
  --s3-bucket your-target-bucket \
  --s3-key lambda-packages/your-lambda-package.zip \
  --publish

Verify the update

To confirm your function was updated successfully, run:

aws lambda get-function --function-name YourLambdaFunctionNameOrARN

Check the Code section in the output — it should show the S3 location of your updated package and the last modified timestamp.

Content sourced from Stack Exchange, question author: Martin Thoma

火山引擎 最新活动