Launching an Amazon EC2 instance from an existing Amazon Machine Image (AMI) is a common way to deploy applications consistently across development, testing, and production environments. However, an AMI can contain outdated operating system packages, vulnerable libraries, unnecessary software, or security configurations that no longer meet an organization's requirements.
If these issues are discovered after an instance has been launched, fixing them can increase deployment time and introduce additional operational work.
A better approach is to scan machine images before using them to create EC2 instances.
Amazon Inspector provides vulnerability scanning capabilities for Amazon EC2 machine images. It helps identify known software vulnerabilities in an AMI before the image is used for deployment. Developers and cloud administrators can review findings, identify affected packages, and decide whether an image is suitable for production.
In this article, we will explore how Amazon Inspector scans EC2 machine images, how to initiate an on-demand scan using the AWS CLI, how to review vulnerability findings, and how to introduce AMI security checks into a deployment workflow.
What Is Amazon Inspector?
Amazon Inspector is an AWS security service that continuously assesses supported AWS workloads for software vulnerabilities and unintended network exposure.
It can scan several types of resources, including:
- Amazon EC2 instances.
- Amazon EC2 machine images.
- Container images stored in Amazon Elastic Container Registry (ECR).
- AWS Lambda functions.
For EC2 machine images, Amazon Inspector identifies known vulnerabilities in supported operating system and software packages.
For example, an AMI created several months ago might contain an outdated version of OpenSSL. A newer security advisory may identify a vulnerability in that version.
An AMI vulnerability scan can help identify the affected package before an instance is created from that image.
The scan results include information such as vulnerability severity, affected files, available fixes, and the associated EBS snapshot.
Why Scan AMIs Before Launching EC2 Instances?
An AMI acts as a template for creating EC2 instances. Any software or package included in the image can become part of every instance launched from it.
Without image scanning, organizations may repeatedly deploy instances containing the same known vulnerabilities.
Consider a deployment pipeline that creates 20 EC2 instances from a single custom AMI.
If the image contains a vulnerable system package, all 20 instances can inherit that vulnerability.
Scanning the image before deployment helps identify this problem earlier.
The main benefits include:
- Early vulnerability detection: Identify known vulnerabilities before launching instances.
- Consistent security standards: Apply the same security checks to development, staging, and production images.
- Reduced remediation effort: Fix vulnerabilities in the source image instead of updating every deployed instance independently.
- Better deployment decisions: Use vulnerability severity and available remediation information when approving images.
- Improved governance: Maintain a repeatable process for reviewing machine images before deployment.
AMI scanning does not replace runtime EC2 security monitoring. A clean image can still become vulnerable when new software is installed or new vulnerabilities are discovered.
Understanding Amazon Inspector AMI Scanning
Amazon Inspector supports two approaches to scanning EC2 machine images.
On-demand AMI scanning
On-demand scanning allows you to initiate a vulnerability assessment for an individual AMI.
This approach is useful when:
- Creating a new custom AMI.
- Updating an existing golden image.
- Reviewing a third-party image before using it.
- Preparing an image for production deployment.
- Investigating a security concern involving a specific AMI.
You do not need to activate Amazon Inspector for an on-demand AMI scan.
However, the scan must target an AMI that you own. An AMI can have only one scan in progress at a time, and an AWS account can have up to 20 on-demand AMI scans in progress simultaneously.
Continuous AMI scanning
Continuous AMI scanning is designed for organizations that regularly create and maintain machine images.
After enabling AMI scanning in Amazon Inspector, you can configure which AMIs should be monitored.
Amazon Inspector evaluates matching images and updates their vulnerability information as relevant security intelligence becomes available.
This is useful when an organization maintains multiple golden images for different operating systems, application environments, and deployment teams.
The difference between these approaches is shown below.
| Feature |
On-demand scanning |
Continuous scanning |
| Scan initiation |
Manually initiated |
Automatically managed |
| Scope |
Individual owned AMI |
Matching account AMIs |
| Inspector activation |
Not required |
Required |
| Best suited for |
Image approval checks |
Ongoing image monitoring |
| Automation |
CLI or API integration |
Continuous monitoring configuration |
Step 1: Identify the EC2 Machine Image
Before starting a scan, identify the AMI that you want to evaluate.
You can list images owned by your AWS account using the AWS CLI.
aws ec2 describe-images \
--owners self \
--query "Images[*].[ImageId,Name,CreationDate,State]" \
--output table
This command retrieves AMIs owned by the current AWS account.
The output includes the image ID, image name, creation date, and current state.
For example, suppose you identify the following image:
AMI ID: ami-1234567890abcdef0
Name: production-web-server
State: available
Keep the AMI ID because it will be required to initiate the vulnerability scan.
Step 2: Start an On-Demand AMI Vulnerability Scan
Amazon Inspector provides the start-on-demand-scan API operation for initiating an AMI scan.
You can execute it through the AWS CLI.
aws inspector2 start-on-demand-scan \
--resource-id ami-1234567890abcdef0 \
--resource-type AMI
The command requests a vulnerability scan for the specified machine image.
The important parameters are:
--resource-id: Identifies the EC2 machine image.
--resource-type: Specifies the resource type as AMI.
After the scan is initiated, Amazon Inspector processes the image and makes the results available through Amazon EC2.
A successful API response means that the scan request was accepted. It does not mean that the scan has already completed.
For production automation, wait until the results are available before evaluating the image against your security policy.
Step 3: Retrieve the AMI Scan Summary
After the scan completes, retrieve its summary using the EC2 describe-images command.
aws ec2 describe-images \
--image-ids ami-1234567890abcdef0 \
--query "Images[].ScanResults" \
--output json
The ScanResults property provides an overview of the vulnerability assessment.
The summary can include:
- HighestFindingSeverityLabel
- FindingScanDate
- InformationalFixAvailableSince
- LowFixAvailableSince
- MediumFixAvailableSince
- HighFixAvailableSince
- CriticalFixAvailableSince
For example, an image might return the following summary:
[
{
"HighestFindingSeverityLabel": "high",
"FindingScanDate": "2026-11-04T08:30:00Z",
"HighFixAvailableSince": "2026-11-02T10:00:00Z"
}
]
This is illustrative output showing the structure of a scan summary.
The highest severity helps security teams understand the most serious vulnerability identified in the image.
However, the summary alone is not sufficient for remediation. You should retrieve the detailed findings before deciding whether the image is acceptable for deployment.
Step 4: Retrieve Detailed Vulnerability Findings
Use the get-image-findings command to retrieve individual vulnerability details.
aws ec2 get-image-findings \
--image-id ami-1234567890abcdef0
The response can contain information such as:
{
"ImageFindings": [
{
"Title": "CVE-2026-12345 - openssl",
"SeverityLabel": "high",
"Score": 7.5,
"FixAvailable": true,
"SnapshotId": "snap-1234567890abcdef0",
"Paths": [
"/usr/lib/libssl.so.3",
"/usr/bin/openssl"
]
}
]
}
The example illustrates how a finding can identify an affected package and its file locations.
Important properties include:
- Title: Identifies the vulnerability and affected package.
- SeverityLabel: Indicates the severity classification.
- Score: Provides the associated vulnerability score.
- FixAvailable: Indicates whether a fix is available.
- SnapshotId: Identifies the EBS snapshot associated with the finding.
- Paths: Shows affected file locations.
The API supports pagination. When the response contains a NextToken, pass it to the next request to retrieve additional findings.
This is important when scanning images with many vulnerabilities.
Step 5: Review Findings Before Approving the AMI
Not every vulnerability requires the same remediation priority.
A production approval process should evaluate severity, exploitability, available fixes, and application requirements.
For example:
| Finding severity |
Recommended action |
| Critical |
Block deployment until reviewed and remediated |
| High |
Prioritize remediation before production use |
| Medium |
Evaluate application exposure and remediation options |
| Low |
Review during regular security maintenance |
| Informational |
Assess whether any action is required |
These are example policy recommendations, not mandatory Amazon Inspector deployment rules.
A vulnerability with an available fix should generally be investigated before approving the image.
However, severity alone should not determine the final decision. Security teams should also consider whether the affected package is reachable, whether the vulnerability applies to the deployed configuration, and whether a safe remediation is available.
Integrating AMI Scanning Into a CI/CD Pipeline
Manual scanning is useful when working with a small number of machine images. However, organizations that build AMIs regularly should automate the scanning and approval process.
A typical deployment workflow can follow this sequence:
- Build a custom AMI using an approved base image.
- Install application dependencies and required security updates.
- Create the AMI.
- Initiate an Amazon Inspector on-demand scan.
- Wait for scan results to become available.
- Retrieve the vulnerability findings.
- Evaluate the results against the organization's security policy.
- Approve the AMI or send it back for remediation.
- Deploy approved images to the target environment.
You can also use Amazon EC2 Allowed AMIs to control which machine images are permitted for use in an account. Its scan-result conditions can help enforce image selection policies based on available AMI scan results.
This provides an additional control beyond relying on developers to select approved images manually.
For reliable automation, the pipeline should distinguish between a scan that has not completed, a scan that failed, and a completed scan that contains unacceptable findings. An unavailable result should never be treated as a successful security check.
Common Mistakes When Scanning EC2 Machine Images
Assuming an accepted scan request means the image is clean
The scan API can accept a request before the assessment has completed.
Always retrieve the results and confirm that they are available before approving the AMI.
Ignoring vulnerabilities with available fixes
A vulnerability marked as high severity with an available fix should not be ignored simply because the application is currently functioning.
Review the affected package and update the image where appropriate.
Scanning an old AMI only once
A scan represents the findings available at a particular point in time.
New vulnerabilities may be discovered later. Continuous AMI scanning or periodic image reassessment can help maintain visibility.
Using the scan summary without reviewing individual findings
The highest severity label provides a quick overview, but it does not explain every affected package.
Review detailed findings to identify the actual remediation work.
Assuming image scanning replaces EC2 instance scanning
An AMI can be clean when created but become vulnerable after software updates or configuration changes.
Continue monitoring running EC2 instances with Amazon Inspector.
Advantages and Disadvantages of Amazon Inspector AMI Scanning
Advantages
- Identifies known software vulnerabilities before instance deployment.
- Supports both individual image scans and continuous monitoring.
- Provides severity classifications and remediation information.
- Integrates with AWS CLI and automated deployment workflows.
- Helps establish consistent security checks for reusable machine images.
Disadvantages
- Scanning introduces an additional step into the image deployment process.
- On-demand scanning requires explicit initiation and result verification.
- Scan findings represent known vulnerabilities and cannot guarantee that an image is completely secure.
- Vulnerability remediation may require rebuilding and retesting an image.
- Scanning incurs additional charges based on the selected scanning approach.
Best Practices for Production Environments
When introducing AMI scanning into production workflows, follow these practices:
- Maintain approved golden images. Build application environments using centrally maintained and regularly updated base images.
- Scan before deployment. Make vulnerability assessment part of the AMI approval process.
- Define severity-based policies. Establish clear rules for critical, high, medium, and low findings.
- Prioritize available fixes. Review vulnerabilities that have vendor-provided remediation options.
- Automate image approval. Integrate scan initiation and result evaluation into CI/CD pipelines.
- Reassess existing images. New vulnerability disclosures can affect images that previously passed security checks.
- Monitor deployed instances. Use EC2 scanning to identify vulnerabilities introduced after launch.
- Control image access. Use IAM permissions and Allowed AMIs to restrict which images teams can launch.
- Track image ownership. Maintain AMI identifiers, creation dates, source images, and scan information.
- Review scanning costs. Monitor on-demand and continuous scanning usage to keep security operations within budget.
Summary
Scanning EC2 machine images before launch helps organizations identify known software vulnerabilities before they become part of deployed infrastructure.
Amazon Inspector provides on-demand and continuous AMI scanning capabilities. Developers can initiate an individual scan using the AWS CLI, retrieve the scan summary through describe-images, and inspect individual vulnerabilities using get-image-findings.
For production environments, AMI scanning should be integrated into the image creation and approval process. Teams should define severity-based policies, prioritize available fixes, and prevent deployment when scan results are missing or violate security requirements.
Image scanning is one part of a broader cloud security strategy. Combining it with continuous EC2 monitoring, approved golden images, IAM controls, and automated deployment checks helps maintain a more consistent security posture across AWS environments.
Join the conversation! Your thoughts help the community grow.