Skip to content

AWS Architecture Best Practices

A cloud resource is a disposable output of code, not a machine you look after. If you can delete any resource and get an identical one back from a template, then scaling, recovery, new environments and audits are all the same operation: run the code again. Names, tags and accounts are the interface that people and automation use to find and govern those outputs, so design them as carefully as an API.

PillarThe question it asks
Operational excellenceCan you change and run it safely?
SecurityWho can do what, and can you prove it?
ReliabilityDoes it recover without you?
Performance efficiencyAre resources the right kind and size?
Cost optimizationDo you pay only for what delivers value?
SustainabilityIs the footprint as small as it can be?

The AWS Well-Architected Framework reviews every workload against these six pillars. They trade off against each other, so decide per workload which ones win: a prototype favors cost, a payment system favors reliability and security. The rest of this sheet is the operational groundwork that several pillars share: automate changes, make them small and reversible, and scale horizontally.

Operations as code templates, not consoles
Small, frequent changes easy to review and revert
Scale horizontally many small, not one big
Test recovery break it on purpose
Stop guessing capacity measure, then autoscale

Tip: Run a Well-Architected review when a design changes, not once before launch. The framework expects architectures to evolve.

AspectPetCattle
CreatedBy hand, in the consoleBy code, from a template
NameUnique and memorableSystematic or generated
When it failsYou repair itYou replace it
ScalingBuy a bigger oneAdd more of them
Config changesApplied in placeShipped as a new version

A pet is a resource someone built by hand and now has to keep alive, because nobody can rebuild it exactly. Cattle are interchangeable: created programmatically, updated by redeploying, and replaced instead of fixed. Default to cattle. Treat every pet as a risk to document or eliminate.

Resources:
Orders: # no TableName: generated
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH

Gotcha: CloudFormation cannot run an update that replaces a custom-named resource, because the old and new copies would need the same name at once. Omit the name, or change it in the same update.

Unique acrossExamples
All accounts in a partitionS3 general purpose bucket names
All CloudFront distributionsAlternate domain names (CNAMEs)
One account, all RegionsIAM users, groups, roles
One account, one RegionLambda functions, RDS instances

A name only has to be unique inside its scope, and the scope differs per service. Regional resources can reuse a name in every Region, which keeps multi-Region stacks symmetrical. Global ones cannot: an IAM role named by a template deployed to two Regions collides with itself. Route 53 follows DNS: a hosted zone has the same name as its domain.

Resources:
Logs:
Type: AWS::S3::Bucket
Properties:
BucketNamespace: account-regional
BucketNamePrefix: acme-logs
# acme-logs-111122223333-eu-west-1-an

Warning: Delete a bucket in the shared global namespace and another account can create the same name and receive requests meant for yours. Empty and keep buckets you still reference, or use the account regional namespace, where only your account can own the name.

SegmentExample values
Organization or projectacme, shop
Environmentdev, staging, prod
Workload or serviceorders, auth
Resource roleapi, queue, db
Region, only if globaleuw1, use1

Pick one order of segments and use it everywhere, so a name can be parsed by a script and guessed by a human. Lowercase letters, digits and hyphens are the only characters every service accepts: S3 rejects uppercase and underscores, and an RDS identifier must start with a letter. Keep names short. S3 buckets and RDS identifiers stop at 63 characters, Lambda function and IAM role names at 64.

<project>-<env>-<workload>-<role>[-<region>]
shop-prod-orders-api Lambda function
shop-prod-orders-db RDS instance
shop-prod-orders-events SQS queue
shop-prod-deploy-euw1 IAM role, per Region

Gotcha: Never put customer names, secrets or other sensitive data in a name. Bucket names appear in URLs, and names leak into logs, ARNs and error messages.

Use a memorable name forUse a generated name for
Organization-wide resources, such as the central log bucketAnything an IaC stack owns
Resources people reference dailyResources that scale horizontally
Long-lived resources with a stable purposeTemporary or ephemeral resources
Names other teams hard-codeShared development environments

Apply the pets-and-cattle test to names. A fixed name is a promise that the resource is a singleton, and it blocks a second copy of the stack in the same account and Region. A generated name such as MyStack-Orders-abcdefghijk1 lets one template deploy any number of times. Code should receive the generated name as configuration instead of hard-coding it.

Outputs:
OrdersTable:
Value: !Ref Orders
Export:
Name: !Sub "${AWS::StackName}-orders-table"

Tip: Put the human meaning in the stack name and tags. Generated names inherit the stack name as a prefix, so shop-prod-orders still shows in the console.

Tag keyAnswers
ProjectWhich workload is this?
EnvironmentIs it safe to delete?
OwnerWho do I ask?
CostCenterWho pays?
ManagedByWhich tool may change it?

Names are fixed at creation and limited in length; tags can change and carry the rest. A resource takes up to 50 user tags, with keys up to 128 characters and values up to 256. Keys and values are case sensitive, so CostCenter and costcenter are two different tags. Write the schema down, keep it in version control, and apply tags from IaC at the stack level, not by hand.

Terminal window
aws cloudformation deploy \
--stack-name shop-prod-orders \
--template-file template.yaml \
--tags Project=shop Environment=prod \
Owner=orders-team CostCenter=1042 \
ManagedBy=cloudformation

Gotcha: A tag does not appear in billing reports until you activate it as a cost allocation tag. A new key can take up to 24 hours to show up for activation, and up to 24 more to activate.

Team sizeIsolation
One to a few developersPrefix per developer in one account
Several environmentsOne account per environment
Beyond 10–15 developersAccount per developer or team

When developers share an account, give each one a namespace: initials or a username in the stack name, plus an Owner tag so strays can be traced and cleaned up. An account is the stronger boundary. Separate accounts give each environment its own security controls, limit the impact of a mistake, split costs, and keep one workload from using up another’s service quotas. At scale, AWS Organizations groups accounts into OUs, Service Catalog offers approved templates, and tag policies standardize keys.

dev-alice-orders-api Alice's Lambda function
dev-bob-orders-api Bob's Lambda function
dev-alice-orders-db Alice's RDS instance
dev-orders-api shared dev
staging-orders-api shared staging
prod-orders-api production

Gotcha: A tag policy in enforcement mode rejects noncompliant tagging requests, which can block autoscaling and provisioning. Start in reporting mode and review the compliance report first.

PracticeWhy
Manage every stack resource through IaCA console edit is invisible to the template
Create a change set before updatingSee replacements before they happen
Detect drift regularlyFind manual changes
DeletionPolicy: Retain on dataStack deletion keeps the resource

Infrastructure as code is what makes cattle possible: the template is the source of truth and the deployed stack is a copy of it. Drift is any difference between the two, usually an urgent console fix nobody ported back. Detect it on a schedule, then either update the template or revert the resource.

Terminal window
aws cloudformation deploy \
--stack-name shop-prod-orders \
--template-file template.yaml \
--no-execute-changeset # review first
aws cloudformation detect-stack-drift \
--stack-name shop-prod-orders
aws cloudformation describe-stack-resource-drifts \
--stack-name shop-prod-orders \
--stack-resource-drift-status-filters \
MODIFIED DELETED

Gotcha: Drift detection only compares properties the template sets explicitly. A property left at its default can be changed by hand without being reported, so set the ones you care about.

The assistant canYour guardrail
Generate IaC from your naming standardStandard lives in a rules file
Recommend tags across resourcesTag policy and code review
Surface drift and unused resourcesRead-only role for reviews
Fetch current AWS guidance over MCPCheck claims against the docs

AI coding assistants such as Kiro extend the cattle approach past resource creation. Put your naming pattern and tag schema in the project rules file, .kiro/steering/*.md for Kiro or CLAUDE.md for Claude Code, so every generated template follows them. The AWS MCP Server lets an agent search AWS documentation and call AWS APIs with your IAM credentials, and marks those requests with the aws:ViaAWSMCPService condition key. Use that key in an SCP to stop agents from deleting production data.

{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Deny",
"Action": ["rds:Delete*", "s3:DeleteBucket"],
"Resource": "*",
"Condition": {
"Bool": {"aws:ViaAWSMCPService": "true"}
}
}]
}

Warning: Keep a human approval step on any change that modifies or removes production resources. An agent runs with your permissions, and a confident wrong plan deletes data as fast as a correct one.