Serverless computing is like calling a ride instead of maintaining a car: the cloud provider manages the infrastructure and allocates resources when needed. In function-as-a-service (FaaS), an event triggers an isolated function rather than an application listening continuously for requests. The provider runs the function in a temporary environment, and the service can scale to zero when idle. section 9.5.1 section 9.12
That convenience changes how you design code. A traditional application moved into a virtual machine or container may continue running much as before; a serverless function must account for an environment that can come and go. Important state belongs in an external database or cloud storage, not in local files or global variables that another invocation might need. section 9.5 section 9.5.2 section 9.12
Pack light and watch the clock:
- Time limits can terminate long jobs. Break a large workload into smaller pieces, or choose another deployment model for tasks that cannot finish within the limit. section 9.5.2
- A cold start adds delay when an inactive function needs a fresh environment. Keep dependencies and deployment packages lightweight to reduce startup work. section 9.5.2
Listing 9.2 The Serverless Function
import json
import boto3
def lambda_handler(event, context): #A
bucket_name = event['Records'][0]['s3']['bucket']['name'] #B
file_name = event['Records'][0]['s3']['object']['key'] #B
print(f"Resizing {file_name} from {bucket_name}...") #C
return { #D
'statusCode': 200,
'body': json.dumps('Image successfully resized!')
}This Python AWS Lambda handler receives an event and extracts an S3 bucket and object key. It logs a resizing message and returns a response; the listing does not implement the resizing itself. section 9.5.1
Serverless is useful when work arrives in bursts or as discrete events:
- Handle a spiky API without keeping capacity running for quiet periods, or trigger a welcome email when a user is added to a database. section 9.5.3
- Schedule a nightly cleanup function, or share a tax-calculation function across applications. section 9.5.3
- Offload heavy work to background functions to keep a device or primary web server responsive, provided the work fits the execution limits. section 9.5.3 section 9.5.2
Choose the tradeoff, not a winner. Serverless can reduce idle costs and infrastructure chores, but proprietary triggers and security roles can make migration expensive. If you need operating-system control or portability, virtual machines or containers may be a better fit. section 9.4.6 section 9.5.4










