AMI allowed instance types
As an AMI owner, you can specify which instance types your AMI supports or does not support. This prevents launches on incompatible instance types. Amazon EC2 enforces the allowed instance types at launch time.
For example, if your AMI requires GPU hardware, you can restrict it to GPU instance types only. If your AMI is incompatible with a specific instance family, you can exclude that family from the allowed instance types.
Contents
How allowed instance types work
You control allowed instance types through the
InstanceTypeSpecification attribute on an AMI. This attribute contains
two lists:
-
SupportedInstanceTypes– The instance types that the AMI supports. Only these instance types can launch with the AMI. -
UnsupportedInstanceTypes– The instance types that the AMI does not support. All other instance types can launch with the AMI.
Amazon EC2 evaluates the specification using the following logic:
-
If
InstanceTypeSpecificationis not set, Amazon EC2 allows all instance types. This is the default behavior. -
If only
SupportedInstanceTypesis set, only the specified instance types are allowed. Amazon EC2 blocks all other instance types. -
If only
UnsupportedInstanceTypesis set, Amazon EC2 allows all instance types except those specified. -
If both lists are set, the instance type must be in
SupportedInstanceTypesand must not be inUnsupportedInstanceTypes.
Wildcard support
Both lists support wildcard patterns using the * character. You
can use wildcards to match multiple instance types without listing each one
individually.
The following table shows examples of wildcard patterns.
| Pattern | Matches |
|---|---|
t3.* |
All sizes within the t3 instance family
(for example, t3.micro,
t3.small, and t3.large) |
p4d.* |
All sizes within the p4d instance family |
g5.* |
All sizes within the g5 instance family |
*xlarge |
Any instance type that is xlarge or larger across all instance families |
*.12xlarge |
Any 12xlarge instance type across all instance families |
Set allowed instance types for an AMI
You can set or change the allowed instance types for an AMI by using the Amazon EC2 console or the AWS Command Line Interface (AWS CLI). You must be the AMI owner to perform this procedure.
View allowed instance types for an AMI
You can view the instance type specification for an AMI by using the Amazon EC2 console or the AWS CLI.
Launch behavior with allowed instance types
When you launch an instance, Amazon EC2 checks whether the specified instance type is compatible with the AMI's instance type specification. If the instance type is not allowed, Amazon EC2 blocks the launch and returns an error.
Example: Blocked launch
The following command attempts to launch a t3.micro instance using
an AMI that does not support t3.micro.
aws ec2 run-instances \ --image-idami-1234567890abcdef0\ --instance-type t3.micro
Amazon EC2 returns the following error:
An error occurred (InvalidParameterCombination) when calling the RunInstances operation: This AMI does not support the specified instance type. Check DescribeImages for InstanceTypeSpecification, and try again.
To resolve this error, choose an instance type that the AMI supports. Use the
describe-images command to view the AMI's instance type
specification.
Considerations
Keep the following information in mind when you use allowed instance types.
-
By default, an AMI has no instance type specification. Amazon EC2 allows all instance types until you explicitly set a specification.
-
Only the AMI owner can set or change the instance type specification.
-
When you copy an AMI using
CopyImage, Amazon EC2 preserves the instance type specification in the new AMI. -
Amazon EC2 enforces the instance type specification as a hard block. If the instance type is not allowed, the launch fails with an
InvalidParameterCombinationerror. -
The specification does not affect existing instances. It applies only to new launches.
-
Launch templates and Auto Scaling groups that reference an AMI with an instance type specification can fail if the configured instance type is not allowed. We recommend verifying compatibility before setting a specification on shared AMIs.
-
The
ReplaceImageInstanceTypeSpecificationaction replaces the entire specification. To add or remove individual instance types, you must include the complete updated specification in the request.