The Secret Life of AWS: The Blueprint (Infrastructure as Code & SAM)
Stop clicking. Start coding. How to clone your application with AWS SAM.
Part 27 of The Secret Life of AWS
Timothy stared at his second monitor, his eyes glazing over.
"London," he muttered. "I need to launch in London."
He had the AWS Console open to the eu-west-2 region. He was trying to manually recreate his entire application—the Lambda functions, the SQS queues, the EventBridge rules, the WAF, the Secrets, and the IAM roles.
"Did I set the timeout to 3 seconds or 5 seconds in Virginia?" he asked himself, clicking back and forth between tabs. "And what was the exact name of that policy?"
Margaret walked by, noticing the frantic switching. "You look like an artist trying to paint the exact same portrait twice," she observed.
"I am," Timothy sighed. "I want to launch my app in Europe. But rebuilding it by hand is taking forever. And I’m terrified I’m going to miss a checkbox."
"You are experiencing the pain of ClickOps," Margaret said gently. "Building by hand is fine for a prototype. But you cannot scale a business on manual labor."
"The secret," she whispered, "is that your infrastructure is not hardware anymore. It is software. And because it is software, you can copy-paste it."
"We need Infrastructure as Code."
The Template
Margaret opened a new file named template.yaml.
"We are going to write a SAM Template," she explained. "Think of it as a recipe. We define the ingredients (Lambda, DynamoDB) and the instructions (Permissions, Triggers), and AWS cooks it for us."
"SAM stands for Serverless Application Model," she continued. "It is a tool designed to make CloudFormation easier. It takes simple, shorthand code and translates it into the complex instructions AWS needs."
She started typing.
Resources:
CheckoutFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: app.lambda_handler
Runtime: python3.9
Events:
CheckoutAPI:
Type: Api
Properties:
Path: /checkout
Method: post
"Look at that," she pointed. "In just 10 lines, we have defined your Lambda function and your API Gateway."
"That's it?" Timothy asked. "I don't have to click 'Create Function' or configure the trigger?"
"No," Margaret smiled. "The code is the infrastructure."
The Deployment
They spent the next hour translating Timothy’s "ClickOps" masterpiece into the YAML template. They added the DynamoDB table, the SQS queue, and even the IAM policies.
"Now for the magic," Margaret said.
She opened the terminal and typed two commands:
sam build
sam deploy --guided
The terminal sprang to life.
"What is it doing?" Timothy asked.
"It is acting as a Transformer," Margaret explained. "The SAM CLI takes your simple template and converts it into a full AWS CloudFormation template. It then hands that blueprint to the CloudFormation service, which builds your actual resources."
The Clone
A few minutes later, the terminal said: Successfully created/updated stack.
Timothy opened the AWS Console for London (eu-west-2).
There it was.
His entire application—every function, every queue, every permission—was perfect. It was an exact clone of the Virginia system.
"It took me two weeks to build that in Virginia," Timothy whispered. "And you just rebuilt it in London in two minutes."
"And if you want to launch in Tokyo?" Margaret asked.
"I just run sam deploy again," Timothy realized.
"Exactly," Margaret beamed. "You are no longer a craftsman, Timothy. You are a manufacturer. You don't build houses one brick at a time anymore. You 3D print them."
The Golden Rule
Margaret raised a finger of warning.
"There is one rule you must follow, Timothy. Now that you have a Blueprint, you must never touch the Console again."
Timothy looked confused. "Why?"
"Because if you change a setting manually in the Console, your Blueprint is no longer accurate. We call that Drift. Your code must be the Single Source of Truth."
"Think of template.yaml as the Constitution for your application," she added. "The Console is just a report on how well reality matches the law."
Timothy nodded solemnly. He looked at his file. It wasn't just code; it was the DNA of his entire business.
Key Concepts
- Infrastructure as Code (IaC): Managing infrastructure using code files rather than manual processes.
- AWS SAM: A framework that simplifies serverless infrastructure. It acts as a "Translator," converting simple syntax into complex CloudFormation templates.
- Reproducibility: The ability to recreate an environment exactly, anywhere in the world.
- Drift: The dangerous situation where your actual infrastructure settings differ from your code blueprint.
Aaron Rose is a software engineer and technology writer at tech-reader.blog and the author of Think Like a Genius.
.jpeg)

Comments
Post a Comment