Managing exposed AWS access keys Part 2: Risk assessment—Evaluating an exposed AWS access key
Discovered an exposed AWS access key? Before you rotate anything, size the risk. This eight-step guide walks you through mapping the key's permissions and exposure window, classifying the severity, checking CloudTrail for unauthorized activity, and deciding whether business needs justify a documented, time-bounded delay in rotation—Part 2 of our three-part series on managing exposed AWS access keys.
Overview
If you've worked through Managing exposed AWS access keys Part 1: Prevention — Stop AWS Access Keys from being exposed, you've already strengthened the controls that keep AWS access keys out of the places they don't belong. This article picks up when a key has been exposed anyway — and walks you through sizing the risk before you decide how to respond.
Step 1: Understand the exposure context
How the key was exposed shapes your urgency:
| Scenario | What It Means | Urgency |
|---|---|---|
| Key found in another customer's repository | A threat actor has obtained and stored your key for use | Immediate |
| Key found on a public website or paste site | Multiple parties may have access to your credentials | Immediate |
| Key detected by automated scanning (GitHub, GitLab, Bitbucket) | Broad exposure; automated attackers may already be testing it | Immediate |
Note: The absence of detected unauthorized activity is not evidence of safety. A threat actor with your credentials could take action at any time.
Step 2: Determine the key's access scope
Identify the AWS Identity and Access Management (IAM) principal:
aws iam list-access-keys --user-name <username>
List all policies:
# Attached managed policies
aws iam list-attached-user-policies --user-name <username>
# Inline policies
aws iam list-user-policies --user-name <username>
# Group memberships (groups may grant additional permissions)
aws iam list-groups-for-user --user-name <username>
Determine what the key is used for:
Understanding what the key actually does in your environment helps you assess the real-world impact of exposure and plan rotation without disrupting production.
Note: The CLI examples below pipe JSON output through jq for readability. If you don't have jq installed, you can substitute the AWS CLI's built-in --query (JMESPath) syntax for most of these transformations.
-
Check when the key was last used and for which service:
aws iam get-access-key-last-used --access-key-id <KEY_ID>This returns the last service accessed, the region, and the timestamp.
-
Review recent API activity in CloudTrail:
aws cloudtrail lookup-events \ --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=<KEY_ID> \ --max-results 50 \ --output json | jq '.Events[].CloudTrailEvent' | jq -r 'fromjson | .eventName' | sort | uniq -c | sort -rnThis gives you the most frequently called APIs — showing what the key actually does day-to-day.
Note: The
cloudtrail lookup-eventsAPI returns events from the last 90 days only. For older exposure windows, use CloudTrail Lake or your CloudTrail log destination in Amazon S3. -
Identify source IPs and user agents (applications using the key):
aws cloudtrail lookup-events \ --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=<KEY_ID> \ --max-results 50 \ --output json | jq '.Events[].CloudTrailEvent' | jq -r 'fromjson | "\(.sourceIPAddress) | \(.userAgent)"' | sort | uniq -c | sort -rnThis tells you which servers, services, or CI/CD pipelines are using the key.
-
Check IAM Access Advisor for service-level usage history:
# Generate the report JOB_ID=$(aws iam generate-service-last-accessed-details --arn arn:aws:iam::<ACCOUNT_ID>:user/<username> --query 'JobId' --output text) # Retrieve the results (wait a few seconds for the report to complete) aws iam get-service-last-accessed-details --job-id $JOB_ID \ --query 'ServicesLastAccessed[?LastAuthenticated!=`null`].[ServiceName,LastAuthenticated]' \ --output tableThis shows all AWS services the user has accessed and when — helpful for understanding the full scope of what the key touches.
-
Look for the key in known configuration locations:
- Application config files, environment variables, or .env files on servers
- CI/CD pipeline secrets (GitHub Actions, CodePipeline, Jenkins)
- AWS CLI profiles (~/.aws/credentials) on developer machines
- Container environment variables or task definitions
- Third-party integrations (monitoring tools, SaaS platforms)
Categorize the access scope:
| Access Scope | Indicators | Risk Level |
|---|---|---|
| Account-wide | AdministratorAccess, wildcard actions ("Action": ""), wildcard resources ("Resource": "") | Highest risk |
| Multi-service | Access to 2+ AWS services (e.g., S3 + EC2 + IAM) | High risk |
| Single-service | Access to exactly one service with limited actions | Moderate risk |
If the exposed key belongs to the AWS account root user (rather than an IAM user), skip the risk classification and rotate the key immediately. Root keys can't be scoped down with a deny policy and can't be replaced with an IAM role. If you can't rotate the key yourself, contact AWS Support.
Step 3: Determine exposure duration
The longer the exposure, the higher the risk.
- Check the IAM Credential Report for key creation date.
- Check notification email or your AWS Health Dashboard for the detection time.
- Exposure window = time between key creation (or last rotation) and detection.
Step 4: Classify the risk level
Look up your risk rating. Your risk rating drives your next action.
| Access Scope | Exposed > 72 hours | Exposed > 24 hours | Exposed ≤ 24 hours |
|---|---|---|---|
| Account-wide* | Critical | Critical | High |
| Multi-service | Critical | High | High |
| Single-service | — | Medium | Low |
* Account-wide (see root-user note in Step 2).
Step 5: Check for unauthorized activity
Review CloudTrail:
-
Open CloudTrail Event History.
-
Filter by AWS access key and enter the exposed key ID.
-
Look for:
- API calls from unrecognized IP addresses
- Activity in AWS regions you don't normally use
- Creation of new IAM users, roles, or access keys
- Amazon EC2 instance launches — especially large instance types, which are commonly used for cryptocurrency mining
- Amazon S3 bucket creation or object downloads
- AWS Lambda function creation or invocation
- AWS CloudTrail logging being stopped or trails being deleted
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=AccessKeyId,AttributeValue=<YOUR_KEY_ID> \
--start-time YYYY-MM-DDTHH:MM:SSZ \
--end-time YYYY-MM-DDTHH:MM:SSZ \
--output json
Note: Both timestamps use ISO 8601 format in UTC — for example, 2026-06-01T00:00:00Z for June 1, 2026 at midnight UTC. On a bash or zsh shell, you can substitute $(date -u +%Y-%m-%dT%H:%M:%SZ) for the --end-time value to query up to the current moment.
Check for unexpected charges:
- Open AWS Cost Explorer.
- Set the date range from exposure start to today.
- Group by Service and Region — look for usage you don't recognize.
Step 6: Identify which applications use the key
Use CloudTrail userAgent analysis to identify dependent applications:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=AccessKeyId,AttributeValue=<KEY_ID> \
--output json | jq '.Events[].CloudTrailEvent' | jq -r 'fromjson | .userAgent' | sort | uniq -c | sort -rn
Also check sourceIPAddress to identify which servers/environments are using the key. This information is critical for planning rotation without breaking production.
Step 7: Document your risk assessment
A written record supports the decisions that come next
| Factor | Your Answer |
|---|---|
| Access scope | Account-wide / Multi-service / Single-service |
| Exposure duration | Hours / Days / Weeks |
| Risk classification | Critical / High / Medium / Low |
| Evidence of unauthorized activity? | Yes / No / Unknown |
| Unexpected charges? | Yes / No |
| Applications depending on this key? | List them |
If your risk is Critical or High, or you see unauthorized activity, proceed immediately to Managing exposed AWS access keys Part 3: Recovery—Responding to an exposed AWS access key.
Step 8: Evaluate risk acceptance against your business needs
In some cases, you may determine that the operational cost of immediate key rotation outweighs the risk posed by the exposure — for example, when a key has narrowly scoped permissions, the exposure window is short, and rotation would cause measurable downtime to a revenue-critical system. This is a business decision that only you can make. This section offers factors to weigh and a framework for documenting your reasoning.
When risk acceptance may be appropriate
Risk acceptance is a deliberate, documented decision — not the absence of action. It's a path you might consider when factors like these are all present:
- The key's access scope is single-service with narrowly scoped actions (no wildcards)
- The exposure duration is ≤ 24 hours
- There is no evidence of unauthorized activity in CloudTrail
- Immediate rotation would cause measurable business disruption (for example, production outage, failed deployments, or revenue loss)
- You have compensating controls in place (see below)
Risk acceptance decision matrix
Use this matrix to weigh the potential impact of an exposed key being used maliciously against your business need to delay rotation:
| Impact if Key is Exploited | Business Disruption from Immediate Rotation | Considerations |
|---|---|---|
| High — account-wide access, data exfiltration possible, resource creation possible | Any level | The exposure risk outweighs almost any rotation cost. Immediate rotation is the strongest option in most cases |
| High — multi-service access with write permissions | Low to moderate disruption | The exposure risk still tends to outweigh the rotation cost. Immediate rotation is the safer path for most teams. |
| Moderate — single-service write access (e.g., S3 PutObject to one bucket) | High disruption (production outage, revenue impact) | Accept the risk conditionally. Implement compensating controls and rotate within 4 hours. |
| Low — read-only access to non-sensitive data | High disruption | Accept the risk short term (up to 24 hours) with compensating controls. |
| Low — read-only access to non-sensitive data | Low disruption | Rotation cost is minimal. Rotating is usually the simpler choice. |
Assessing impact of exposed key exploitation
To judge how severe the consequences could be if a threat actor uses your exposed key, consider:
| Impact Factor | Questions to Ask | High Impact Indicators |
|---|---|---|
| Data sensitivity | What data can this key access? Customer PII? Financial records? Intellectual property? | Access to any regulated or customer-facing data |
| Reach | Can this key create resources, modify infrastructure, or escalate privileges? | Write access to IAM, EC2, Lambda, or CloudFormation |
| Financial exposure | Could an unauthorized party run up notable charges (for example, cryptocurrency mining or large Amazon EC2 fleets)? | Ability to launch compute resources or create expensive services |
| Lateral movement | Could this key be used to gain access to other accounts or services? | Cross-account role assumption, access to secrets/credentials stores |
| Compliance exposure | Would unauthorized access trigger regulatory notification requirements? | Access to PII, PHI, PCI data, or audit-relevant systems |
| Reputational risk | Could exploitation result in customer-visible impact or public disclosure? | Access to customer-facing services or data stores |
Compensating controls (required for risk acceptance)
If you choose to accept risk temporarily, implement these controls before delaying rotation:
Restrict the key's permissions
Apply a deny policy to limit the key to the specific actions and resources currently in use:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Deny",
"NotAction": ["s3:GetObject", "s3:PutObject"],
"Resource": "*"
}]
}
Add IP restrictions
If you know the legitimate source IPs, add a condition to your deny policy that excludes them. The example below is a policy fragment; attach the condition block to a deny statement in the same policy you used in item 1 above.
{
"Condition": {
"NotIpAddress": {
"aws:SourceIp": ["203.0.113.0/24"]
}
}
}
Enable enhanced monitoring
Set up a Amazon CloudWatch alarm or Amazon EventBridge rule to alert on API calls from unrecognized IP addresses that use this key.
Set a hard rotation deadline
Document the exact time by which the key will be rotated, regardless of business conditions. Aim for a deadline no later than 24 hours out.
Document your risk acceptance decision
If you choose to accept risk, record the following:
| Factor | Your Answer |
|---|---|
| Business justification for delayed rotation | (specific service/revenue impact) |
| Maximum tolerable exposure window | (hours until mandatory rotation) |
| Compensating controls implemented | (list each control) |
| Monitoring in place to detect exploitation | Yes / No |
| Rotation deadline (hard stop) | (exact date/time UTC) |
| Decision owner (name and role) | (person accountable) |
| Escalation plan if unauthorized activity detected | (immediate actions) |
Important: Risk acceptance is time-bounded, not permanent. It is a decision with a hard rotation deadline. If unauthorized activity is detected at any point, the acceptance is void — proceed immediately to Managing exposed AWS access keys Part 3: Recovery—Responding to an exposed AWS access key.
Need Help? Sign Up for AWS Security Incident Response
Even with strong preventive controls in place, security incidents can still happen. When they do, having a plan for expert support in advance can shorten your time to containment.
AWS Security Incident Response is a managed service that helps you prepare for, respond to, and recover from security events in your AWS environment. The service provides:
- 24/7 access to AWS security experts who can guide you through active incidents, including credential compromise, unauthorized access, and data exposure.
- Automated triage and investigation that accelerates response times by surfacing relevant findings from GuardDuty, Security Hub, and other detection services into a centralized case management workflow.
- Pre-built response playbooks for common incident types, so your team isn't starting from scratch when an event occurs.
- Coordinated remediation support to help you contain threats, remove attacker persistence, and restore your environment to a known-good state.
- Proactive readiness features including incident simulations and response planning to ensure your team is prepared before an incident strikes.
Whether you have a dedicated security operations team or a small team wearing multiple hats, AWS Security Incident Response gives you the expertise and tooling to handle security events confidently and efficiently.
Learn more about AWS Security Incident Response
Managing Exposed Access Keys
See more blogs part of the managing exposed Access keys series:
-
Managing exposed AWS access keys Part 1: Prevention — Stop AWS Access Keys from being exposed
Stop AWS access keys from being exposed before they become a liability. This first article in our three-part series on managing exposed AWS access keys focuses on prevention, with nine practical steps—from replacing long-lived keys with IAM roles and enabling MFA to setting up GuardDuty, real-time alerting, and least-privilege controls—plus a checklist to help your team reduce the risk and blast radius of credential compromise.
-
Managing exposed AWS access keys Part 2: Risk assessment—Evaluating an exposed AWS access key
Discovered an exposed AWS access key? Before you rotate anything, size the risk. This eight-step guide walks you through mapping the key's permissions and exposure window, classifying the severity, checking CloudTrail for unauthorized activity, and deciding whether business needs justify a documented, time-bounded delay in rotation—Part 2 of our three-part series on managing exposed AWS access keys.
-
Managing exposed AWS access keys Part 3: Recovery—Responding to an exposed AWS access key
Discovered an exposed AWS access key? This third installment in our series is a step-by-step recovery playbook for containing the damage—from locking down the compromised key and rooting out unauthorized activity to safely rotating credentials and hardening your account against a repeat incident.
- Language
- English

Relevant content
- Accepted Answer
asked 2 years ago
asked 4 years ago
AWS OFFICIALUpdated 7 months ago
AWS OFFICIALUpdated 2 years ago