如何在CloudFormation模板中为EC2实例开启T2Unlimited模式?
Yep, you absolutely can enable T2Unlimited for your t2.nano EC2 instance using CloudFormation—you just won’t find the setting directly in the AWS::EC2::Instance resource properties. Instead, you need to use the AWS::EC2::InstanceCreditSpecification resource to configure the CPU credit mode for your instance.
Here's how to set it up:
- First, define your t2.nano EC2 instance as you normally would, specifying the
InstanceTypeast2.nano. - Add a separate
AWS::EC2::InstanceCreditSpecificationresource that references your EC2 instance's ID, and set theCPUCreditsproperty to"unlimited".
Example CloudFormation YAML template:
AWSTemplateFormatVersion: "2010-09-09" Resources: MyT2NanoInstance: Type: AWS::EC2::Instance Properties: InstanceType: t2.nano ImageId: ami-xxxxxxx # Replace with your desired AMI ID # Add other required properties like KeyName, SecurityGroups, etc. MyInstanceCreditSpec: Type: AWS::EC2::InstanceCreditSpecification Properties: InstanceId: !Ref MyT2NanoInstance CPUCredits: "unlimited"
Why this works:
The T2Unlimited mode is managed as a separate credit specification configuration for EC2 instances, not a core property of the instance itself. That’s why you won’t see it listed in the AWS::EC2::Instance documentation—this setting lives in the dedicated credit specification resource instead.
Once deployed, this template will launch a t2.nano instance with T2Unlimited mode enabled, allowing it to burst beyond its baseline CPU capacity whenever needed.
内容的提问来源于stack exchange,提问作者Yuki Inoue

