Skip to content
Kuza Ndoto Academy

Security Best Practices

Beginner → IntermediateChapter 2 · Page 7 of 305 min readUpdated 15 Nov 2026

Most AWS security incidents that hit learners and small teams come from a handful of avoidable mistakes: an unprotected root user, leaked access keys, over-broad permissions or resources left open to the internet. This page gathers the habits that prevent them, in order of importance.

1. Protect identities

  • Root user: MFA on, no access keys, used only for root-only tasks.
  • MFA for every human: require MFA in IAM Identity Center for all users. Passkeys and security keys resist phishing better than SMS codes.
  • One identity per person: never share logins. If three students work on a group project, each gets their own user, so CloudTrail shows who did what and access can be removed individually.
  • Least privilege: give people and apps only what they need, and review permissions regularly. IAM shows when each permission was last used, which helps you remove unused ones.

2. Prefer temporary credentials over access keys

An access key (an access key ID beginning with AKIA plus a secret access key) is a long-lived password for the AWS API. Anyone who has it can act as you until it is deleted. Temporary credentials expire on their own, usually within hours, so a leak does far less damage.

SituationUse instead of long-lived keys
You, using the CLI on your laptopIAM Identity Center with aws configure sso and aws sso login
Code running on EC2An IAM role via an instance profile
A Lambda functionIts execution role
Containers on ECS or EKSTask roles (ECS) or EKS Pod Identity / IAM roles for service accounts
GitHub Actions deploying to AWSAn IAM role trusted through OpenID Connect (OIDC), so no secret is stored in GitHub

If you truly need an access key, for example for an old tool, create it for a user with minimal permissions, rotate it regularly and delete it when no longer needed. You can audit keys from the CLI:

aws iam list-access-keys --user-name report-uploader
{ "AccessKeyMetadata": [ { "UserName": "report-uploader", "AccessKeyId": "AKIAIOSFODNN7EXAMPLE", "Status": "Active", "CreateDate": "2026-03-02T08:15:42+00:00" } ] }

(Example output. AKIAIOSFODNN7EXAMPLE is the dummy key ID used in AWS documentation.)

3. Keep secrets out of code and Git

Warning

Never commit access keys, passwords or API secrets to GitHub, even in a private repository that might become public later. Automated bots scan public commits continuously, and leaked AWS keys are often abused within minutes, typically to launch expensive servers for cryptocurrency mining. Deleting the commit is not enough, because the key stays in Git history and in forks.

Add a .gitignore before your first commit:

.env
*.pem
.aws/
credentials
__pycache__/

Store application secrets, such as a database password or the API key a payments provider uses to sign its callbacks, in AWS Secrets Manager or as a SecureString in Systems Manager Parameter Store, and read them at runtime with the app's role:

import json

import boto3

secrets = boto3.client("secretsmanager")
response = secrets.get_secret_value(SecretId="prod/payments/callback")
config = json.loads(response["SecretString"])
callback_key = config["api_key"]   # use it, but never print or log it

The role needs permission for secretsmanager:GetSecretValue on that one secret's ARN, and nothing broader.

If a key leaks

  1. Deactivate and delete the key immediately in IAM.
  2. Check CloudTrail event history for what the key was used to do.
  3. Look for unknown resources (EC2 instances, Lambda functions, IAM users) in every Region, and delete them.
  4. Contact AWS Support from the console, especially if there are unexpected charges.

AWS also watches for its keys on public sites and may email you and attach a restrictive quarantine policy to the affected user. Treat that email as an emergency, not as spam.

4. Close the network doors

Warning

A security group rule allowing SSH (port 22) or RDP (port 3389) from 0.0.0.0/0 means anyone on the internet can try to log in. Automated scanners find such servers within minutes. Allow only your own IP address (My IP in the console), or better, use EC2 Instance Connect or Systems Manager Session Manager, which need no open inbound port at all.

  • Never make a database publicly accessible. Allow its port only from the app servers' security group.
  • Keep S3 Block Public Access turned on at the account level. Serve public websites through CloudFront rather than a public bucket.
  • Put servers that do not need to be reached directly in private subnets (see Amazon VPC).

5. Encrypt and log

  • Encryption at rest: new S3 objects are encrypted by default. Turn on EBS encryption by default for your Region, and enable encryption when creating RDS databases. AWS KMS manages the keys.
  • Encryption in transit: use HTTPS everywhere. AWS Certificate Manager issues free public TLS certificates for use with CloudFront and load balancers.
  • Logging: CloudTrail keeps 90 days of management events in its event history; create a trail to keep logs longer in S3.
  • Detection: turn on GuardDuty to spot threats such as credentials used from unusual places, and use Security Hub to check your account against best-practice standards. These services have their own charges after any trial period, so check pricing first.

A weekly checklist

  1. Any unexpected charges in Billing? Any budget alerts?
  2. Any running resources you forgot, in any Region?
  3. Any access keys older than 90 days, or unused?
  4. Any security group with SSH or RDP open to 0.0.0.0/0?
  5. Any S3 bucket or database reachable from the internet that should not be?

Key points

  • Lock the root user with MFA and require MFA for every person.
  • Use roles and Identity Center for temporary credentials; treat long-lived access keys as a last resort.
  • Never commit keys or secrets; store secrets in Secrets Manager or Parameter Store.
  • Never open SSH to the world or make buckets and databases public by accident.
  • Encrypt data, keep CloudTrail logs and react quickly to any leak.
Up next · Security & AccessThe AWS CLI & SDKs (boto3)Manage AWS from the terminal and from Python code.
→

Tip: use the ← and → keys to move between pages.