More Info:
Your AMI age should be more than configured number of days. This ensures that your EC2 instances deployed are secure and reliable.Risk Level
LowAddress
Operational Maturity, Reliability, SecurityCompliance Standards
- APRA CPS 234 (Australia)
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- FedRAMP
- HITRUST CSF
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST CSF
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SOC2
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
The AMI age should not exceed the configured age is a common misconfiguration in AWS. You can remediate this issue by following the below steps:
- Log in to your AWS Management Console.
- Go to the EC2 Dashboard.
- Click on the “AMIs” option from the left-hand navigation panel.
- Identify the AMI which has exceeded the configured age.
- Select the AMI and click on the “Actions” button.
- Choose the “Deregister” option from the drop-down list.
- Confirm the deregistration by clicking on the “Deregister” button in the confirmation dialog box.
- Once the AMI is deregistered, you can create a new AMI with the latest updates and configurations.
Using CLI
Using CLI
To remediate the “AMI Age Should Not Exceed the Configured Age” misconfiguration in AWS, you can follow the below steps using AWS CLI:
-
First, identify the AMIs that have exceeded the configured age by running the below command:
Note: Replace
<configured_age>with the age limit in the formatyyyy-mm-dd. -
Once you have identified the AMIs, you can deregister them using the below command:
Note: Replace
<image_id>with the ID of the AMI that you want to deregister. - Finally, to automate this process, you can create a Lambda function that runs the above commands on a scheduled basis to ensure that AMIs do not exceed the configured age limit.
Using Python
Using Python
To remediate the AMI Age misconfiguration in AWS using Python, you can follow the steps below:Note: This is just a sample code and it may need to be modified based on your specific requirements. Also, make sure to test the code thoroughly before running it in a production environment.
- Identify the misconfigured AMIs by checking their age against the configured age.
- Create a Lambda function in AWS that uses the Boto3 library to identify the misconfigured AMIs.
- Use the EC2 client in Boto3 to get a list of all the AMIs in your AWS account.
- Loop through the list of AMIs and check the age of each one against the configured age.
- If an AMI is older than the configured age, deregister it using the EC2 client.
- Set up a CloudWatch event to trigger the Lambda function at a regular interval to ensure that all misconfigured AMIs are remediated in a timely manner.
Using Terraform
Using Terraform
- Replace
INSTANCE_TYPE,SUBNET_ID,SECURITY_GROUP_ID,KEY_PAIR_NAME, andINSTANCE_NAMEwith your values. - Ensure the AMI resolved by
data.aws_ami.RECENT_AMAZON_LINUX2is not older than 180 days when you apply (check in the AWS Console oraws ec2 describe-images). - This change will force replacement of
aws_instance.EC2_INSTANCE_NEEDS_NEW_AMI(and similarly any launch templates/ASGs you update), causing instance recreation/outage unless you use a rolling deployment strategy.
terraform plan should show the old EC2 resource(s) being replaced with new ones using the newer AMI ID, and no remaining resources referencing the out-of-date AMI.
