0
0
AWScloud~5 mins

Lambda pricing model in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
AWS Lambda pricing is based on how many times your code runs and how long it takes to run. You pay only for the compute time you use, measured in milliseconds, and the number of requests.
When you want to run code without managing servers and pay only for the actual usage.
When you have unpredictable workloads that can scale automatically without upfront costs.
When you want to build event-driven applications that respond to changes or triggers.
When you want to run small pieces of code quickly without worrying about infrastructure.
When you want to optimize costs by paying only for the compute time your code consumes.
Commands
This command shows your current Lambda usage and limits, helping you understand your free tier and usage.
Terminal
aws lambda get-account-settings
Expected OutputExpected
{ "AccountLimit": { "TotalCodeSize": 80530636800, "CodeSizeUnzipped": 262144000, "CodeSizeZipped": 52428800, "ConcurrentExecutions": 1000, "UnreservedConcurrentExecutions": 1000 }, "AccountUsage": { "TotalCodeSize": 12345678, "FunctionCount": 5 } }
This command runs your Lambda function once, which counts as one request and uses compute time based on how long it runs.
Terminal
aws lambda invoke --function-name example-function output.txt
Expected OutputExpected
{ "StatusCode": 200, "ExecutedVersion": "$LATEST" }
--function-name - Specifies which Lambda function to run
This command retrieves the average execution duration of your Lambda function, which affects your cost because you pay for compute time.
Terminal
aws cloudwatch get-metric-statistics --namespace AWS/Lambda --metric-name Duration --dimensions Name=FunctionName,Value=example-function --start-time 2024-06-01T00:00:00Z --end-time 2024-06-01T01:00:00Z --period 60 --statistics Average
Expected OutputExpected
{ "Label": "Duration", "Datapoints": [ { "Timestamp": "2024-06-01T00:00:00Z", "Average": 150.0, "Unit": "Milliseconds" } ] }
--metric-name - Specifies the metric to check, here the execution duration
--dimensions - Filters metrics for the specific Lambda function
Key Concept

If you remember nothing else, remember: AWS Lambda pricing depends on how many times your function runs and how long each run takes.

Common Mistakes
Ignoring the function's memory size when estimating cost
Lambda pricing also depends on the memory allocated, which affects the compute cost per millisecond.
Always consider the memory size setting because higher memory increases the price per millisecond.
Assuming Lambda is free after the free tier
The free tier covers 1 million requests and 400,000 GB-seconds per month; usage beyond that is charged.
Monitor your usage and understand the free tier limits to avoid unexpected charges.
Summary
Use 'aws lambda get-account-settings' to check your Lambda usage and limits.
Invoke your Lambda function to generate requests and compute time usage.
Check execution duration with CloudWatch metrics to understand compute time costs.