AWS AMI Management
Careful AMI management is critical in ensuring vulnerabilities are not present in an environment, but it can become increasingly difficult to manage hundreds, if not thousands of AMI and images across a large number of cloud accounts. Guardrails provides a large family of AMI and image controls and policies to help organizations achieve their management objectives.
AMI Policy Families
Guardrails provides a wide range of AMI and Image policies and controls. You can find a full list in the aws-ec2 mod on the Hub. This guide focuses on two families:
AWS > EC2 > AMI > *
| Policy Type | Description |
|---|---|
| Active | Set an AMI to Active if it meets the sub-policy conditions. |
| Approved | Set an AMI to Approved if it meets the sub-policy conditions. |
| Tags | Define and apply a tagging template to AMI. |
| Usage | Set limits on the number of AMI that can exist. |
AWS > EC2 > Instance > Approved > Image > *
While a much smaller family of policies, this allows admins to define approved instances based on the AMI used to boot. Note that these do not follow a standard formula as this use case is specific to EC2.
| Policy Type | Description |
|---|---|
| AMI IDs | Define AMI that are approved to be used to launch EC2 instances. |
| Publishers | Define AWS account IDs whose images may be used to launch EC2 instances. |
Prerequisites
- Access to the Turbot Guardrails console with
Turbot/Adminpermissions or higher. - The
aws-ec2mod installed.
Example 1: AMI Age Limits
In this example, any AMI older than 60 days is set to Inactive. We'll use Check mode so Guardrails generates an alarm for administrator review rather than deleting the AMI.
[!TIP] When configuring compound policies, set the child policies first, then set the primary policy last. This ensures the control doesn't start evaluating until the criteria are fully defined.
Step 1: Set the Age Threshold
Click New Policy Setting in the top right of the Policies page to open the Create Policy Setting form.
For the Policy Type, search for ami active age and select Age (AWS > EC2 > AMI > Active > Age). For the Resource, select the account or folder where the setting will live. Because this policy type has many values, the Setting is a dropdown; select Force inactive if age > 60 days and click Create.

Step 2: Enable the Active Check
Click New Policy Setting again. For the Policy Type, search for ami active and select Active (AWS > EC2 > AMI). Select the same Resource scope, choose Check: Active, and click Create.

Guardrails immediately runs controls against AMI at and below the setting in the resource hierarchy.
Step 3: Review the Results
Navigate to Controls in the left sidebar, search for AMI Active, and select AWS > EC2 > AMI > Active. This shows a list of control states and their applicable resources. AMI older than 60 days are in an Alarm state.
Example 2: Dynamic AMI Approval
The policy AWS > EC2 > AMI > Approved > Usage can be turned into a calculated policy to allow dynamic approvals based on metadata such as tags, encryption, volume size, and more.
In this example, assume an organization wants to approve an AMI only if it is both not public and has the tag security_approved: approved.
Step 1: Create the Calculated Policy
Click New Policy Setting. For the Policy Type, search for ami approved usage and select Usage (AWS > EC2 > AMI > Approved). Select the Resource scope.
Beside the Setting label, click Enable calculated mode, then click Launch calculated policy builder. In the builder, use the following GraphQL Input Query to get the tags and public setting of the AMI:
{
resource {
data
turbot {
tags
}
}
}
Use the following Nunjucks Template. It first checks if the image is public, then checks for the approval tag. Notice how we initialize a variable as Approved and change it to Not approved if conditions match, which is a simple way to evaluate multiple conditions:
{% set result = "Approved" %}
{% if $.resource.data.Public == true %}
{% set result = "Not approved" %}
{% endif %}
{% if $.resource.turbot.tags['security_approved'] != "approved" %}
{% set result = "Not approved" %}
{% endif %}
{{ result }}
Click Update to return to the form with the query and template populated, then click Create.
Step 2: Enable the Approved Check
Click New Policy Setting. For the Policy Type, search for ami approved and select Approved (AWS > EC2 > AMI). Select the same Resource scope, choose Check: Approved, and click Create.
Once set, Guardrails evaluates existing AMI. Navigate to Controls, search for AMI Approved, and select AWS > EC2 > AMI > Approved to see the results.
See the Guardrails Samples Repo for more calculated policy examples using Terraform.
Example 3: Approve EC2 Instances by AMI ID
You can restrict which AMI are allowed to launch EC2 instances. The use case of approving instances based on the AMI publisher is very similar: replace AWS > EC2 > Instance > Approved > Image > AMI IDs with AWS > EC2 > Instance > Approved > Image > Publishers.
Step 1: Define Allowed AMI IDs
Click New Policy Setting. For the Policy Type, search for instance approved ami ids and select the policy type. Select the Resource scope. Because this policy is an array, the Setting shows a YAML editor; enter a list of allowed AMI IDs:
- ami-jc81a385
- ami-fa345678
Click Create.
Step 2: Configure the Image Approval Rule
Create a policy setting for AWS > EC2 > Instance > Approved > Image. Set it to Approved if ImageId in Image > AMI IDs.
Step 3: Enable the Approved Check
Create a policy setting for AWS > EC2 > Instance > Approved. Set it to Check: Approved.
Guardrails re-evaluates all instances based on the AMI ID used to boot. Navigate to Controls, search for AWS EC2 Instance Approved, and check the results.
Advanced IAM Restrictions
The following examples require Guardrails to be managing IAM within the target account.
Allow Admins to Publish AMI
By default, publishing AMI is not allowed for users with roles managed by Guardrails unless the user has the AWS/Superuser permission. To allow admins to publish:
Create a policy setting for AWS > EC2 > Permissions > Levels > Ami Publishing Administration and set it to Admin.
This triggers a re-calculation of AWS > Turbot > Permissions > Compiled > Service Permissions > @turbot/aws-ec2. Users who have AWS/Admin assigned are now able to publish AMI.
Allow Only Admins to Change Instance Tags
Some organizations have automation to tag new resources and want to restrict non-admin users from adding, removing, or changing tags. By default, tagging changes are allowed at the Operator level.
Use Permission Modifiers to restrict the subset of EC2 permissions related to tagging.
Create a policy setting for AWS > EC2 > Permissions > Levels > Modifiers and set the value to the following YAML list:
- "ec2:createtags": admin
- "ec2:deletetags": admin
Once the policy setting is created, AWS > Turbot > Permissions > Compiled > Service Permissions > @turbot/aws-ec2 re-runs to reflect the changes.
Next Steps
- Create a Calculated Policy: Step-by-step guide for creating calculated policies.
- Active: Understand the Active guardrail pattern.
- Approved: Understand the Approved guardrail pattern.
- AWS Permissions: Learn about permission levels and modifiers.