Specify CPU options for an Amazon EC2 instance - Amazon Elastic Compute Cloud

Specify CPU options for an Amazon EC2 instance

You can specify CPU options during instance launch.

The following examples describe how to specify the CPU options when using the launch instance wizard in the EC2 console and the run-instances AWS CLI command, and the create launch template page in the EC2 console and the create-launch-template AWS CLI command. For EC2 Fleet or Spot Fleet, you must specify the CPU options in a launch template.

The following examples are for an r5.4xlarge instance type, which has the following default values:

  • Default CPU cores: 8

  • Default threads per core: 2

  • Default vCPUs: 16 (8 * 2)

  • Valid number of CPU cores: 2, 4, 6, 8

  • Valid number of threads per core: 1, 2

Disable simultaneous multithreading

To disable simultaneous multithreading (SMT), also known as hyper-threading, specify 1 thread per core.

Console
To disable SMT during instance launch
  1. Follow the Launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console procedure and configure your instance as needed.

  2. Expand Advanced details, and select the Specify CPU options check box.

  3. For Core count, choose the number of required CPU cores. In this example, to specify the default CPU core count for an r5.4xlarge instance, choose 8.

  4. To disable SMT, for Threads per core, choose 1.

  5. In the Summary panel, review your instance configuration, and then choose Launch instance. For more information, see Launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console.

AWS CLI
To disable SMT during instance launch

Use the run-instances AWS CLI command and specify a value of 1 for ThreadsPerCore for the --cpu-options parameter. For CoreCount, specify the number of CPU cores. In this example, to specify the default CPU core count for an r5.4xlarge instance, specify a value of 8.

aws ec2 run-instances \ --image-id ami-1a2b3c4d \ --instance-type r5.4xlarge \ --cpu-options "CoreCount=8,ThreadsPerCore=1" \ --key-name MyKeyPair

Specify a custom number of vCPUs at launch

You can customize the number of CPU cores and threads per core for the instance.

The following example launches an r5.4xlarge instance with 4 vCPUs.

Console
To specify a custom number of vCPUs during instance launch
  1. Follow the Launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console procedure and configure your instance as needed.

  2. Expand Advanced details, and select the Specify CPU options check box.

  3. To get 4 vCPUs, specify 2 CPU cores and 2 threads per core, as follows:

    • For Core count, choose 2.

    • For Threads per core, choose 2.

  4. In the Summary panel, review your instance configuration, and then choose Launch instance. For more information, see Launch an Amazon EC2 instance using the launch instance wizard in the Amazon EC2 console.

AWS CLI
To specify a custom number of vCPUs during instance launch

Use the run-instances AWS CLI command and specify the number of CPU cores and number of threads in the --cpu-options parameter. You can specify 2 CPU cores and 2 threads per core to get 4 vCPUs.

aws ec2 run-instances \ --image-id ami-1a2b3c4d \ --instance-type r5.4xlarge \ --cpu-options "CoreCount=2,ThreadsPerCore=2" \ --key-name MyKeyPair

Alternatively, specify 4 CPU cores and 1 thread per core (disable SMT) to get 4 vCPUs:

aws ec2 run-instances \ --image-id ami-1a2b3c4d \ --instance-type r5.4xlarge \ --cpu-options "CoreCount=4,ThreadsPerCore=1" \ --key-name MyKeyPair

Specify a custom number of vCPUs in a launch template

You can customize the number of CPU cores and threads per core for the instance in a launch template.

The following example creates a launch template that specifies the configuration for an r5.4xlarge instance with 4 vCPUs.

Console
To specify a custom number of vCPUs in a launch template
  1. Follow the Create a launch template by specifying parameters procedure and configure your launch template as needed.

  2. Expand Advanced details, and select the Specify CPU options check box.

  3. To get 4 vCPUs, specify 2 CPU cores and 2 threads per core, as follows:

    • For Core count, choose 2.

    • For Threads per core, choose 2.

  4. In the Summary panel, review your instance configuration, and then choose Create launch template. For more information, see Store instance launch parameters in Amazon EC2 launch templates.

AWS CLI
To specify a custom number of vCPUs in a launch template

Use the create-launch-template AWS CLI command and specify the number of CPU cores and number of threads in the CpuOptions parameter. You can specify 2 CPU cores and 2 threads per core to get 4 vCPUs.

aws ec2 create-launch-template \ --launch-template-name TemplateForCPUOptions \ --version-description CPUOptionsVersion1 \ --launch-template-data file://template-data.json

The following is an example JSON file that contains the launch template data, which includes the CPU options, for the instance configuration for this example.

{ "NetworkInterfaces": [{ "AssociatePublicIpAddress": true, "DeviceIndex": 0, "Ipv6AddressCount": 1, "SubnetId": "subnet-7b16de0c" }], "ImageId": "ami-8c1be5f6", "InstanceType": "r5.4xlarge", "TagSpecifications": [{ "ResourceType": "instance", "Tags": [{ "Key":"Name", "Value":"webserver" }] }], "CpuOptions": { "CoreCount":2, "ThreadsPerCore":2 } }

Alternatively, specify 4 CPU cores and 1 thread per core (disable SMT) to get 4 vCPUs:

{ "NetworkInterfaces": [{ "AssociatePublicIpAddress": true, "DeviceIndex": 0, "Ipv6AddressCount": 1, "SubnetId": "subnet-7b16de0c" }], "ImageId": "ami-8c1be5f6", "InstanceType": "r5.4xlarge", "TagSpecifications": [{ "ResourceType": "instance", "Tags": [{ "Key":"Name", "Value":"webserver" }] }], "CpuOptions": { "CoreCount":4, "ThreadsPerCore":1 } }