What is Infrastructure as Code (IaC) in the context of serverless?

Answer

Infrastructure as Code (IaC) means defining cloud resources in machine-readable configuration files rather than configuring them manually through a console. For serverless, IaC is especially critical because a single application may involve dozens of Lambda functions, API Gateway routes, IAM roles, DynamoDB tables, and S3 buckets — manually maintaining these is error-prone and non-reproducible. IaC benefits: reproducibility (recreate identical environments for dev/staging/prod), version control (track infrastructure changes in Git), code review (review infrastructure changes like code), rollback (revert to previous infrastructure state). Serverless IaC options: AWS CloudFormation (native AWS, verbose YAML/JSON), AWS SAM (CloudFormation extension with serverless shortcuts), Serverless Framework (provider-agnostic serverless.yml), AWS CDK (TypeScript/Python code generates CloudFormation), Terraform (multi-cloud HCL configuration). SAM and CDK are the current AWS recommendations.