Serverless Application Model (SAM) in AWS - Time & Space Complexity
We want to understand how the time to deploy a serverless app changes as the app grows.
Specifically, how does adding more functions or resources affect deployment time?
Analyze the time complexity of deploying a SAM template with multiple Lambda functions.
sam deploy --template-file template.yaml --stack-name my-stack --capabilities CAPABILITY_IAM
# template.yaml defines multiple AWS::Serverless::Function resources
# Each function has its own code and configuration
# Deployment packages and CloudFormation stack updates happen here
This sequence deploys a serverless app with several Lambda functions using SAM.
Look at what happens repeatedly during deployment:
- Primary operation: Packaging and uploading each Lambda function's code to S3.
- How many times: Once per function defined in the template.
- Secondary operation: CloudFormation stack update calls to create or update each resource.
- How many times: Depends on the number of resources, including functions and others.
As you add more functions, the deployment time grows roughly in direct proportion.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | About 10 package uploads + 1 stack update |
| 100 | About 100 package uploads + 1 stack update |
| 1000 | About 1000 package uploads + 1 stack update |
Pattern observation: Each added function adds one packaging and upload operation, so time grows linearly.
Time Complexity: O(n)
This means deployment time grows roughly in direct proportion to the number of functions you deploy.
[X] Wrong: "Adding more functions won't affect deployment time much because it's all one command."
[OK] Correct: Each function's code must be packaged and uploaded separately, so more functions mean more work and longer deployment.
Understanding how deployment time grows helps you plan and explain scaling serverless apps clearly and confidently.
"What if we used a single shared deployment package for multiple functions? How would the time complexity change?"