0
0
AWScloud~5 mins

Serverless Application Model (SAM) in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Serverless Application Model (SAM)
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As you add more functions, the deployment time grows roughly in direct proportion.

Input Size (n)Approx. API Calls/Operations
10About 10 package uploads + 1 stack update
100About 100 package uploads + 1 stack update
1000About 1000 package uploads + 1 stack update

Pattern observation: Each added function adds one packaging and upload operation, so time grows linearly.

Final Time Complexity

Time Complexity: O(n)

This means deployment time grows roughly in direct proportion to the number of functions you deploy.

Common Mistake

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

Interview Connect

Understanding how deployment time grows helps you plan and explain scaling serverless apps clearly and confidently.

Self-Check

"What if we used a single shared deployment package for multiple functions? How would the time complexity change?"