Deploying a Lambda Function
Lambda runs your code in response to events with no servers — you pay only when it runs.
Syntax
aws lambda update-function-code --function-name NAME --zip-file fileb://fn.zipAWS Lambda runs a function in response to an event and then shuts down. There are no servers to manage and you pay per millisecond of execution. It scales from zero to thousands of concurrent runs automatically.
Anatomy of a function
- Handler — the entry point AWS calls, receiving an
eventandcontext. - Runtime — Node, Python, Go, etc.
- Trigger — what invokes it: API Gateway, S3 upload, queue message, schedule.
Deploying is simply uploading your code (a zip or container image) and pointing a trigger at it.
Example
# Package and deploy a Node.js Lambda
zip -r fn.zip index.js node_modules
aws lambda update-function-code \
--function-name myapp-api \
--zip-file fileb://fn.zip \
--publishWhen to use it
- An image-processing service runs as a Lambda triggered by S3 uploads, resizing each photo without any always-on infrastructure.
- A team uses Lambda to run a nightly data export to S3 triggered by a scheduled EventBridge rule, paying only for the 30 seconds it executes.
- A webhook handler for GitHub events runs as a Lambda function behind API Gateway, handling zero to thousands of calls per minute without scaling concerns.
More examples
Create and deploy a Lambda function
Packages the handler into a zip and creates the Lambda function with a 30-second timeout and 256 MB of memory.
zip function.zip index.js
aws lambda create-function \
--function-name my-handler \
--runtime nodejs20.x \
--role arn:aws:iam::123456789012:role/lambda-exec \
--handler index.handler \
--zip-file fileb://function.zip \
--timeout 30 \
--memory-size 256Update function code in place
Replaces the Lambda deployment package with a new zip and publishes a new version in a single command.
zip function.zip index.js
aws lambda update-function-code \
--function-name my-handler \
--zip-file fileb://function.zip \
--publishInvoke Lambda and inspect output
Synchronously invokes the function with a test payload and writes the response to a file for inspection.
aws lambda invoke \
--function-name my-handler \
--payload '{"key":"value"}' \
--cli-binary-format raw-in-base64-out \
response.json
cat response.json
Discussion