AWS Builder Center

AWS Security Best Practices: A Practical Guide to Protecting Your Cloud Infrastructure

Learn how to secure AWS workloads using least-privilege IAM, multi-factor authentication, encryption, network controls, continuous monitoring, and automated security checks. This practical guide covers essential configurations and actionable steps to build a more secure AWS environment.

AWS Security Best Practices: A Practical Guide to Protecting Your Cloud Infrastructure

Introduction

Cloud computing enables organizations to build scalable, reliable, and cost-effective applications. However, moving workloads to the cloud does not eliminate security risks. Misconfigured permissions, exposed credentials, publicly accessible resources, and insufficient monitoring can leave cloud environments vulnerable to attacks.
Amazon Web Services (AWS) provides a wide range of security services and features to help protect applications, data, and infrastructure. To use them effectively, developers must understand how to configure these controls and integrate security into their everyday workflows.
In this article, we will explore practical AWS security best practices that developers, cloud engineers, and administrators can apply to build a more secure cloud environment.

1. Understand the AWS Shared Responsibility Model

Security in AWS is a shared responsibility between AWS and the customer.
AWS is responsible for security of the cloud, including the physical infrastructure, hardware, networking infrastructure, and facilities that support its services.
Customers are responsible for security in the cloud, including appropriate identity permissions, data protection, application security, and resource configuration. The exact division of responsibilities depends on the AWS service being used.
For example:
  • AWS manages the underlying physical infrastructure of Amazon EC2.
  • Customers are responsible for securing their EC2 operating systems, applications, and security group rules.
  • AWS manages the infrastructure for Amazon S3, while customers configure bucket access, data protection, and permissions.
Best practice: Understand the security responsibilities associated with every AWS service you use. Do not assume that AWS automatically secures every aspect of your application.

2. Apply the Principle of Least Privilege

Identity and Access Management (IAM) controls who can access AWS resources and which actions they can perform.
The principle of least privilege means granting only the permissions required to complete a specific task.
For example, an application that only needs to read files from an S3 bucket should not receive full administrative access to the AWS account.

Recommended practices

  • Avoid using the AWS root user for everyday activities.
  • Enable multi-factor authentication (MFA) for the root user and privileged identities.
  • Prefer IAM roles and temporary credentials over long-lived access keys.
  • Use narrowly scoped IAM policies.
  • Review permissions regularly and remove unnecessary access.
  • Use IAM Access Analyzer to help identify unintended access.

Example: Restrict S3 access

The following IAM policy allows reading objects from one specified S3 bucket. Replace YOUR_BUCKET_NAME with your bucket name.
1
2
3
4
5
6
7
8
9
10
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
This policy grants object-reading permission only for objects in the specified bucket. It does not grant permission to list the bucket or modify its contents.
Attach the policy to an appropriate IAM identity or role, and verify that other policies do not grant broader access.
Important: This is an illustrative identity policy, not a complete access-control configuration. Effective permissions also depend on other applicable policies and controls.

3. Secure Credentials and Authentication

Exposed credentials are a common cause of cloud security incidents. Accidentally committing access keys to a public Git repository can allow unauthorized users to access AWS resources.

Recommended practices

  • Never hardcode AWS access keys or passwords in source code.
  • Never commit .env files containing secrets to Git.
  • Use IAM roles for workloads running on AWS.
  • Use IAM Identity Center or federated access for human users where appropriate.
  • Store application secrets in AWS Secrets Manager or AWS Systems Manager Parameter Store.
  • Rotate credentials when required by your security policy or incident response procedures.
  • Revoke exposed credentials immediately and investigate their potential use.
For local development, use a configured AWS CLI profile or an approved identity-federation workflow instead of embedding credentials in application code.
To verify which identity your AWS CLI session is using, run:
1
aws sts get-caller-identity
This command returns information about the AWS account and identity associated with the active credentials.

4. Protect Data with Encryption

Data protection is essential for applications that store customer information, business records, authentication details, or other sensitive content.
AWS supports encryption in transit and encryption at rest across many services.

Encryption in transit

Use HTTPS and TLS to protect data moving between clients, applications, and services.
Recommended measures include:
  • Configure HTTPS for public web applications.
  • Use secure connections between application components.
  • Avoid transmitting sensitive information over unencrypted protocols.
  • Keep certificates and TLS configurations up to date.

Encryption at rest

Use supported encryption options for stored data, including:
  • Amazon S3 server-side encryption.
  • Amazon EBS volume encryption.
  • Amazon RDS encryption.
  • AWS Key Management Service (AWS KMS) for managing encryption keys.
For example, you can enable default server-side encryption for an S3 bucket with AWS CLI:
1
2
3
4
aws s3api put-bucket-encryption \
--bucket YOUR_BUCKET_NAME \
--server-side-encryption-configuration \
'{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'
This example configures S3-managed server-side encryption for objects uploaded to the bucket. Choose SSE-KMS instead when your requirements call for KMS key controls, auditing, or other key-management capabilities.
Best practice: Determine your data classification requirements before selecting encryption, retention, and key-management settings.

5. Configure Network Security Properly

Network security controls help prevent unauthorized access to applications and internal resources.
AWS provides several mechanisms for controlling network traffic, including Amazon VPC, security groups, network ACLs, AWS Network Firewall, and AWS WAF.

Recommended practices

  • Place resources in an appropriately designed VPC.
  • Keep databases and internal services in private subnets when public access is unnecessary.
  • Restrict security group inbound rules to required sources and ports.
  • Avoid exposing SSH (port 22) and RDP (port 3389) to the entire internet.
  • Use AWS Systems Manager Session Manager or another approved administrative access mechanism where appropriate.
  • Use AWS WAF to help protect supported web applications against common web exploits.
  • Review public IP addresses, load balancers, and internet-facing endpoints regularly.
For example, a security group for an application server should allow only the necessary application traffic from approved sources. Administrative access should be restricted separately.
Best practice: Start with deny-by-default network design and allow only the traffic your application actually needs.

6. Enable Logging, Monitoring, and Threat Detection

Security controls are more effective when suspicious activity can be detected and investigated.
AWS provides several services for visibility and threat detection.
AWS servicePrimary purpose
AWS CloudTrailRecords account activity and API events
Amazon CloudWatchCollects metrics, logs, and alarms
Amazon GuardDutyDetects potential threats using supported data sources
AWS Security HubCentralizes security findings and security posture information
AWS ConfigRecords resource configurations and evaluates supported rules

Recommended practices

  1. Enable and appropriately configure CloudTrail logging.
  2. Protect audit logs from unauthorized modification or deletion.
  3. Configure CloudWatch alarms for important operational and security events.
  4. Enable GuardDuty in relevant accounts and Regions.
  5. Use Security Hub to centralize findings where appropriate.
  6. Review AWS Config evaluations for insecure or noncompliant resource configurations.
  7. Establish an incident response process for investigating alerts.
Logging alone does not prevent attacks. Logs should be retained appropriately, monitored, and connected to a response process.
Best practice: Ensure that someone or some automated process is responsible for reviewing and acting on security findings.

7. Protect Amazon S3 Resources

Amazon S3 is commonly used for application uploads, backups, static websites, analytics, and data storage. Incorrect access settings can unintentionally expose sensitive information.

Recommended practices

  • Enable S3 Block Public Access unless public access is explicitly required.
  • Use least-privilege bucket policies and IAM permissions.
  • Enable appropriate encryption settings.
  • Use versioning for important data where recovery requirements justify it.
  • Apply lifecycle policies to manage data retention and storage costs.
  • Enable access logging or other suitable audit mechanisms when required.
  • Consider S3 Object Lock when immutable retention is necessary.
  • Review cross-account access and bucket policies regularly.
For a private data bucket, verify that public access is blocked at the appropriate levels and that the bucket policy does not grant unintended access.
Do not assume that enabling encryption makes a publicly accessible bucket safe. Encryption and access control address different risks.

8. Automate Security Checks

Manual security reviews are valuable, but they can miss configuration errors as infrastructure changes.
Infrastructure as Code (IaC) allows teams to define and review cloud resources using version-controlled templates.
Security checks can be incorporated into development and deployment pipelines.

Useful approaches

  • Use AWS CloudFormation Guard to evaluate supported infrastructure templates against policies.
  • Scan Terraform or CloudFormation configurations for security issues.
  • Use AWS Config rules to evaluate deployed resource configurations.
  • Review IAM policies before deployment.
  • Run dependency and container image vulnerability scans.
  • Require appropriate approval for production changes.
  • Use automated testing to detect publicly exposed resources or overly broad permissions.
For example, a deployment pipeline can validate infrastructure templates before applying changes. If a template violates an organizational security policy, the pipeline can stop the deployment for review.
Automation reduces repetitive work and helps make security a consistent part of software delivery.

9. Organize and Govern Multiple AWS Accounts

For larger applications and teams, separating workloads into multiple AWS accounts can help isolate environments and improve governance.
AWS Organizations and AWS Control Tower provide capabilities for managing multi-account environments.

Recommended practices

  • Separate production, development, and testing workloads when appropriate.
  • Apply Service Control Policies (SCPs) to establish organization-level permission boundaries.
  • Central
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article