Part 29 of Learn AWS from Scratch

Cost and Good Architecture

The series finale. Where your money goes on the network, the tools that watch your bill, the Well-Architected Framework, building everything from a template with CloudFormation, Systems Manager, and where to go after this series, with a hands-on.

In this article
  1. Where does the network money go?
  2. Where's the caching?
  3. Tools that watch your bill
  4. The Well-Architected Framework
  5. CloudFormation: your infrastructure in a file
  6. Systems Manager: running your servers
  7. Applications you can't change
  8. Services worth knowing
  9. Hands-on: a whole stack from a file, and a budget you'll keep
  10. Summary
  11. Test yourself
  12. What you've learned

You've come a long way since part one. In this final part we answer two questions that apply to everything we built: how much does it cost? and is it designed well? Then we turn it all into a file you can rebuild with one command.

Where does the network money go?

Most people plan for servers and storage, then get surprised by data transfer. Prices here are approximate for US Regions:

Region Availability Zone 1 EC2 EC2 Free with private IPs Availability Zone 2 EC2 Between zones: $0.01 per GB each way In from the internet: free Internet About $0.09 per GB Other Region From $0.02 per GB
Data going into AWS is free, and within a zone over private addresses too. You pay when it crosses a boundary: between zones, between Regions, or out to the internet.
Direction Approx. price per GB
Into AWS from the internet Free
Inside one Availability Zone, using private IPs Free
Between Availability Zones $0.01 in each direction
Between Regions From about $0.02, and it varies by Region
Out to the internet About $0.09 and falling with volume, with the first 100 GB a month free

Small numbers add up quickly. Six things that cut them:

  • Use private IPs inside the VPC instead of public ones, and note that every public IPv4 address also has an hourly charge.
  • Put CloudFront in front of your application. Data from AWS to CloudFront is free, and out through it costs less than going out directly.
  • Add a gateway endpoint for S3 and DynamoDB. It's free, and it spares you NAT charges per GB.
  • One NAT gateway per Availability Zone, so traffic doesn't cross zones to reach it.
  • Keep chatty services close. Balance this against availability, though, as splitting across zones is worth paying for.
  • Compress what you send, and cache it as far forward as you can.

Where's the caching?

Each layer saves work for the ones behind it, so the further forward the better, and we've seen them all:

Layer Tool Saves
The edge CloudFront The whole trip, for content that's the same for everyone
The API API Gateway cache The function and the database
The application ElastiCache Heavy queries and calculations
The database DAX or a read replica Reads from the main database

Tools that watch your bill

Tool What it does
Cost Explorer Charts your spending by service, account and tag, forecasts it, and recommends Savings Plans
Budgets Alerts you when you reach or are forecast to reach a limit, and monitoring is free
Cost Anomaly Detection Uses machine learning to spot unusual spending, at no charge
Cost Optimization Hub Gathers recommendations for savings in one place: resizing, idle resources and more
Compute Optimizer Recommends suitable sizes based on your actual use
Cost and Usage Report The most detailed data on your costs and usage, delivered as files to S3 for you to analyze. AWS Data Exports creates similar exports with the columns you choose

And the first step is tags: without an env or team tag, you won't know who's spending what. And tags only reach your cost reports once you activate them as cost allocation tags in the billing console.

Quick savings

Action Where we saw it
Resize oversized servers Part three
Commit with Savings Plans, and use Spot for what tolerates interruption Part four
Stop dev servers at night, for example with Instance Scheduler on AWS This part
Lifecycle rules for S3 Part sixteen
Set a retention period on logs Part twenty-five
Delete orphaned disks, snapshots and load balancers Part five

The Well-Architected Framework

AWS has summarized what it's learned from its customers in six pillars. Consider it a review for any design:

Pillar The question We covered it in
Operational excellence Can you run it and improve it? Monitoring and templates
Security Are data and access protected? IAM and encryption
Reliability Does it survive failures and recover? Scaling and recovery
Performance efficiency Are you using the right resources? Caching and choosing a database
Cost optimization Are you paying for what you don't need? This part
Sustainability Are you reducing your consumption and its impact? Right sizing and Graviton

The pillars pull against each other at times: more copies mean better reliability and higher cost. The aim isn't to max out everything, but to make the trade-off knowingly.

  • AWS Well-Architected Tool: a free tool in the console that asks you questions about your workload and shows the risks.
  • Trusted Advisor: checks your account against best practices. On the free plan you get service limits and a few security and fault-tolerance checks, and the rest need a paid support plan. Note that AWS is changing its support plans, with Developer and Business ending on January 1, 2027 in favor of Business Support+.

CloudFormation: your infrastructure in a file

So far we've created everything by hand or by command. What if you could describe it all in a file? AWS CloudFormation reads a template and builds a stack of resources, in the right order, and:

  • Repeatable: the same environment for development, testing and production.
  • Reviewable: the template sits in Git like code, and you review its changes.
  • Controlled: a change set shows what will change before it happens, and drift detection reveals manual changes.
  • Clean: deleting a stack deletes everything in it, so nothing's left billing you.
  • Free: you pay only for the resources it creates.

Infrastructure Composer lets you draw a template visually, and AWS CDK writes it in Python or TypeScript. A service role lets a developer deploy a stack without having permission over the resources themselves.

Systems Manager: running your servers

AWS Systems Manager manages fleets of servers through an agent, already installed on Amazon Linux, and an IAM role:

Tool What it does
Session Manager A terminal with no SSH port and no keys, with sessions logged
Run Command One command across a thousand servers
Patch Manager Applies updates on a schedule
Maintenance Windows Sets when these things are allowed to happen
Automation Ready documents for common tasks, like Config remediation

Applications you can't change

Not every application can be rewritten, and you can often make an old one more reliable from the outside, without touching its code:

Problem Solution
One server that can fail An Auto Scaling group of one with a health check, or automatic recovery, which brings it back on new hardware with the same addresses
Load that overwhelms it CloudFront in front of it, for whatever can be cached
Too many database connections RDS Proxy, which only needs a new endpoint
A database that can go down Multi-AZ, which keeps the same endpoint
Clients allowing fixed addresses through their firewalls The two static addresses of Global Accelerator

Services worth knowing

A last group that deserves a line each:

Service What it's for
SES Sending email, for transactions and marketing, with protection for your reputation
AWS Batch Batch jobs at any scale, on EC2 or Fargate, with no 15-minute limit like Lambda
AWS Outposts AWS servers in your own data center, for when the data must stay with you
Amazon AppFlow Moving data from SaaS applications such as Salesforce into S3 or Redshift, with no code
AWS Amplify Quickly building and hosting web and mobile applications
Service Catalog A catalog of approved services, so teams deploy only what's allowed
License Manager Tracks software licenses, such as Oracle and SAP, across accounts
Device Farm Testing apps on real phones and tablets hosted by AWS

If you read older articles, Amazon Pinpoint reached its end of support on October 30, 2026. AWS points to SES for email, and to AWS End User Messaging for SMS and push notifications. AWS Proton also reached its end of support, on October 7, 2026, though the exam guide still lists it.

High performance computing

When you need thousands of processors working together:

Need Tools
Compute A cluster placement group, with Enhanced Networking or EFA, and Spot where possible
Storage FSx for Lustre, Instance Store and S3
Orchestration AWS Batch or AWS ParallelCluster
Moving data Direct Connect or DataSync

Hands-on: a whole stack from a file, and a budget you'll keep

Write a small template with a bucket and an SNS topic. From CloudShell:

Bash
cat > stack.yaml <<'EOF'
AWSTemplateFormatVersion: "2010-09-09"
Description: A small stack from the AWS series
Parameters:
  Env:
    Type: String
    Default: dev
Resources:
  Files:
    Type: AWS::S3::Bucket
    Properties:
      VersioningConfiguration:
        Status: Enabled
      Tags:
        - Key: env
          Value: !Ref Env
  Alerts:
    Type: AWS::SNS::Topic
Outputs:
  BucketName:
    Value: !Ref Files
EOF

aws cloudformation deploy --stack-name series-stack --template-file stack.yaml

aws cloudformation describe-stack-resources --stack-name series-stack \
  --query "StackResources[].[LogicalResourceId,ResourceType,ResourceStatus]" \
  --output table

CloudFormation built both resources and named them itself. Now change one value. It updates only what changed, without touching the rest:

Bash
aws cloudformation deploy --stack-name series-stack \
  --template-file stack.yaml --parameter-overrides Env=prod

BUCKET=$(aws cloudformation describe-stacks --stack-name series-stack \
  --query "Stacks[0].Outputs[0].OutputValue" --output text)

aws s3api get-bucket-tagging --bucket $BUCKET \
  --query "TagSet[?Key=='env'].Value" --output text

It prints prod. Now the nicest part, deleting everything with one command:

Bash
aws cloudformation delete-stack --stack-name series-stack
aws cloudformation wait stack-delete-complete --stack-name series-stack
echo "Everything is gone"

Finally, one thing to keep: a budget of $10 a month that warns you when you're forecast to exceed 80% of it. Replace the email address with yours:

Bash
EMAIL=[email protected]
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)

cat > budget.json <<'EOF'
{
  "BudgetName": "series-monthly",
  "BudgetLimit": {"Amount": "10", "Unit": "USD"},
  "TimeUnit": "MONTHLY",
  "BudgetType": "COST"
}
EOF

cat > notify.json <<EOF
[{
  "Notification": {
    "NotificationType": "FORECASTED",
    "ComparisonOperator": "GREATER_THAN",
    "Threshold": 80,
    "ThresholdType": "PERCENTAGE"
  },
  "Subscribers": [{"SubscriptionType": "EMAIL", "Address": "$EMAIL"}]
}]
EOF

aws budgets create-budget --account-id $ACCOUNT \
  --budget file://budget.json \
  --notifications-with-subscribers file://notify.json

aws budgets describe-budgets --account-id $ACCOUNT \
  --query "Budgets[].[BudgetName,BudgetLimit.Amount,BudgetLimit.Unit]" --output table

If you get AccessDenied, your IAM user may need billing access, which the root user enables from the account settings.

Summary

  • Data transfer is the hidden cost: between zones, between Regions, and out to the internet.
  • Budgets and Cost Anomaly Detection warn you before the bill does.
  • The Well-Architected Framework has six pillars, and the point is to make trade-offs knowingly.
  • CloudFormation turns your infrastructure into a reviewable, deletable file.
  • Systems Manager manages your servers without SSH.

Test yourself

Before you move on, try these questions to check you've got this part. Each one is a practical scenario, and the explanation appears once you answer.

Question 1 of 7

Two EC2 servers in the same Availability Zone exchange terabytes a month by calling each other's public IP addresses, and the transfer shows up on the bill. What's the simplest fix?

Show the answer

Correct answer: B

Data between servers in one Availability Zone is free over private addresses, while traffic through a public address is charged.

  • A: Crossing zones is charged in each direction.
  • C: A NAT gateway adds a charge for every gigabyte.
  • D: The size of the server doesn't change what the transfer costs.

Review: Where does the network money go? in this part, and EC2 On-Demand Instance Pricing on the AWS site.

Question 2 of 7

A small team wants an email when this month's AWS spending is forecast to pass its limit, not after the bill arrives. What fits?

Show the answer

Correct answer: A

A budget can alert on forecasted spending as well as actual spending, and the monitoring itself is free.

  • B: This charts your spending and forecasts it, but someone has to go and look.
  • C: This recommends suitable sizes, and sends no spending alerts.
  • D: This records settings, not spending.

Review: Tools that watch your bill in this part, and Managing your costs with AWS Budgets in the AWS docs.

Question 3 of 7

A team wants to review one workload's design against AWS's best practices, by answering questions about it and seeing the risks. What fits?

Show the answer

Correct answer: D

The tool asks you questions about your workload, and shows you the risks. It's free in the console.

  • A: This scans what you run for known vulnerabilities, and doesn't review a design.
  • B: This checks your account's resources by itself, and doesn't ask about a workload.
  • C: This records who called what.

Review: The Well-Architected Framework in this part, and AWS Well-Architected Tool FAQs on the AWS site.

Question 4 of 7

A team wants the same environment in development and production from one file in Git, to see what an update will change before it happens, and to know if someone edits a resource by hand. What fits?

Show the answer

Correct answer: C

A template builds the same stack every time and sits in Git. Change sets show what will change, and drift detection reveals manual edits.

  • A: This runs commands on servers, and doesn't describe infrastructure.
  • B: This repeats a server's contents, not the network and other resources around it.
  • D: This records settings and judges them, but doesn't build anything.

Review: CloudFormation: your infrastructure in a file in this part, and Update CloudFormation stacks using change sets and Detect unmanaged configuration changes to stacks and resources with drift detection in the AWS docs.

Question 5 of 7

A company must apply security updates across 500 EC2 servers, only during a Saturday night slot, and with no SSH access. Which two tools fit? (Choose two.)

Show the answer

Correct answer: B + E

Patch Manager applies the updates, and Maintenance Windows sets when they're allowed to happen.

  • A: This gives you a terminal, one session at a time.
  • C: This stores settings and simple secrets.
  • D: This recommends suitable sizes based on your use.

Review: Systems Manager: running your servers in this part, and AWS Systems Manager Patch Manager and AWS Systems Manager Maintenance Windows in the AWS docs.

Question 6 of 7

A finance team wants the cost of each team in detailed files it can analyze itself. Resources are already tagged with team, but the tag doesn't appear in the reports. Which two steps fit? (Choose two.)

Show the answer

Correct answer: B + E

Tags only reach cost reports once they're activated, and the Cost and Usage Report delivers the most detailed data as files in S3.

  • A: This records resource settings, not costs.
  • C: This recommends suitable sizes.
  • D: This records operations inside resources, not costs.

Review: Tools that watch your bill in this part, and What are AWS Cost and Usage Reports? and Organizing and tracking costs using AWS cost allocation tags in the AWS docs.

Question 7 of 7

An old application runs on one EC2 server, and its clients connect to that server's address. The code can't be changed. If the hardware fails, the server must come back by itself with the same addresses. What fits?

Show the answer

Correct answer: C

Recovery brings the server back on new hardware, keeping its instance ID and its private, public and Elastic IP addresses.

  • A: This is a rewrite, and the code can't change.
  • B: The replacement is a new server, with new addresses.
  • D: You'd have to restore it by hand, onto a new server with new addresses.

Review: Applications you can't change in this part, and Automatic instance recovery in the AWS docs.

What you've learned

Twenty-nine parts in nine sections. Look at what you can do now:

Section You can now
Fundamentals Understand the global infrastructure and control permissions
Servers and their storage Run a server, choose its pricing and keep its data
High availability and scaling Build an application that survives failures and grows by itself
Databases Choose the right database and speed it up
Networking and content delivery Design a private network and deliver content around the world
Object storage Store anything in S3 at the right price, and securely
Modern applications Separate services, and run containers and serverless
Data and AI Analyze your data and add AI to your application
Security and operations Monitor, protect, recover and control your costs

Where to go from here

  • Build something real. A small project of your own teaches you more than any article, even a little site with an API.
  • Try the comprehensive test. It picks random questions from every part, so you can see what's stuck and what to review.
  • Read the FAQs. Each service's FAQ page is a short, rich and accurate summary.
  • Consider a certification. Solutions Architect Associate covers most of what's in this series, and the exam tests how you choose between services. Read each question for its deciding phrase, such as "lowest cost" or "least operational effort", and eliminate the wrong answers first. Its official exam guide lists every domain and service.
  • Follow the changes. AWS changes quickly, and several things in this series changed even as it was being written. Check the docs before any decision.

Thanks for coming along to the end, and good luck with what you build.