Specify CPU options for an Amazon EC2 instance (original) (raw)

You can specify CPU options during or after instance launch.

Tasks

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 EC2 instance using the launch instance wizard in the console procedure and configure your instance as needed.
  2. Expand Advanced details, and select theSpecify CPU options checkbox.
  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, choose8.
  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 EC2 instance using the launch instance wizard in the console.

AWS CLI

To disable SMT during instance launch

Use the run-instances AWS CLI command and specify a value of1 for ThreadsPerCore for the--cpu-options parameter. ForCoreCount, specify the number of CPU cores. In this example, to specify the default CPU core count for anr7i.4xlarge instance, specify a value of8.

aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --instance-type r7i.4xlarge \
    --cpu-options "CoreCount=8,ThreadsPerCore=1" \
    --key-name my-key-pair

PowerShell

To disable SMT during instance launch

Use the New-EC2Instance command and specify a value of1 for ThreadsPerCore for the-CpuOptions parameter. ForCoreCount, specify the number of CPU cores. In this example, to specify the default CPU core count for anr7i.4xlarge instance, specify a value of8.

New-EC2Instance `
    -ImageId 'ami-0abcdef1234567890' `
    -InstanceType 'r7i.4xlarge' `
    -CpuOptions @{CoreCount=8; ThreadsPerCore=1} `
    -KeyName 'my-key-pair'
Note

To disable SMT for an existing instance, follow the process shown in Change CPU options for your EC2 instance, and change the number of threads that run per core to 1.

Specify a custom number of vCPUs at launch

You can customize the number of CPU cores and threads per core when you launch an instance from the EC2 console or AWS CLI. The examples in this section use anr5.4xlarge instance type, which has the following default settings:

Instances launch with the maximum number of vCPUs available for the instance type by default. For this instance type, that's 16 total vCPUs (8 cores running 2 threads each). For more information about this instance type, see Memory optimized instances.

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 EC2 instance using the launch instance wizard in the console procedure and configure your instance as needed.
  2. Expand Advanced details, and select theSpecify CPU options checkbox.
  3. To get 4 vCPUs, specify 2 CPU cores and 2 threads per core, as follows:
    • For Core count, choose2.
    • For Threads per core, choose2.
  4. In the Summary panel, review your instance configuration, and then choose Launch instance. For more information, see Launch an EC2 instance using the launch instance wizard in the 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-0abcdef1234567890 \
    --instance-type r7i.4xlarge \
    --cpu-options "CoreCount=2,ThreadsPerCore=2" \
    --key-name my-key-pair

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

aws ec2 run-instances \
    --image-id ami-0abcdef1234567890 \
    --instance-type r7i.4xlarge \
    --cpu-options "CoreCount=4,ThreadsPerCore=1" \
    --key-name my-key-pair

PowerShell

To specify a custom number of vCPUs during instance launch

Use the New-EC2Instance 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.

New-EC2Instance `
    -ImageId 'ami-0abcdef1234567890' `
    -InstanceType 'r7i.4xlarge' `
    -CpuOptions @{CoreCount=2; ThreadsPerCore=2} `
    -KeyName 'my-key-pair'

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

New-EC2Instance `
    -ImageId 'ami-0abcdef1234567890' `
    -InstanceType 'r7i.4xlarge' `
    -CpuOptions @{CoreCount=4; ThreadsPerCore=1} `
    -KeyName 'my-key-pair'

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 examples in this section use an r5.4xlarge instance type, which has the following default settings:

Instances launch with the maximum number of vCPUs available for the instance type by default. For this instance type, that's 16 total vCPUs (8 cores running 2 threads each). For more information about this instance type, see Memory optimized instances.

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 theSpecify CPU options checkbox.
  3. To get 4 vCPUs, specify 2 CPU cores and 2 threads per core, as follows:
    • For Core count, choose2.
    • For Threads per core, choose2.
  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 theCpuOptions 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-0abcdef1234567890"
    }],
    "ImageId": "ami-0abcdef1234567890",
    "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-0abcdef1234567890"
    }],
    "ImageId": "ami-0abcdef1234567890",
    "InstanceType": "r5.4xlarge",
    "TagSpecifications": [{
        "ResourceType": "instance",
        "Tags": [{
            "Key":"Name",
            "Value":"webserver"
        }]
    }],
    "CpuOptions": {
        "CoreCount":4,
        "ThreadsPerCore":1
    }
}

PowerShell

To specify a custom number of vCPUs in a launch template

Use the New-EC2LaunchTemplate.

New-EC2LaunchTemplate `
    -LaunchTemplateName 'TemplateForCPUOptions' `
    -VersionDescription 'CPUOptionsVersion1' `
    -LaunchTemplateData (Get-Content -Path 'template-data.json' | ConvertFrom-Json)

Change CPU options for your EC2 instance

As your needs change over time, you might want to change the configuration of CPU options for an existing instance. Each thread that runs on your instance is known as a virtual CPU (vCPU). You can change the number of vCPUs that run for an existing instance in the Amazon EC2 console, AWS CLI, API, or SDKs. The instance state must beStopped before you can make this change.

Console

To change the number of active vCPUs for an instance
  1. Open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.
  2. In the left navigation pane, chooseInstances. This opens the list of instances that are defined for the current AWS Region.
  3. Select the instance from the Instances list. Alternatively, you can select the instance link to open the instance detail page.
  4. If the instance is running, you must stop it before you proceed. Choose Stop instance from theInstance state menu.
  5. To change your vCPU configuration, choose Change CPU options from Instance settings in the Actions menu. This opens the Change CPU options page.
  6. Choose one of the following CPU options to change the configuration for your instance.
    None
    This option resets your instance to the default number of vCPUs for your instance type. The default is to run all threads for all CPU cores.
    Specify CPU options
    This option enables configuration of the number of vCPUs that are running on your instance.
  7. If you selected Specify CPU options, theActive vCPU configuration is displayed.
    • The first selector configures the number of threads that run for each CPU core. To disable simultaneous multithreading, you can change the number of threads that run per core to 1.
    • The second selector configures the number of CPUs that are running for your instance.
      The following fields are updated dynamically, as you make changes to the CPU option selectors.
    • Active vCPUs: The number of CPU cores multiplied by the threads per core, based on the selections that you made. For example, if you selected 2 threads and 4 cores, that would equal 8 vCPUs.
    • Total vCPUs: The maximum number of vCPUs for the instance type. For example, for anm6i.4xlarge instance type, this is 16 vCPUs (8 cores running 2 threads each).
  8. To apply your updates, chooseChange.

AWS CLI

To change the number of active vCPUs for an instance

Use the modify-instance-cpu-options command and specify the number of CPU cores that run in the --core-count parameter, and the number of threads that run per core in the--threads-per-core parameter.

The following examples shows two possible configurations on anm6i.4xlarge instance type to run 8 vCPUs on the specified instance. The default for this instance type is 16 vCPUs (8 cores running 2 threads each).

Example 1: Run 4 CPU cores with 2 threads per core, for a total of 8 vCPU.

aws ec2 modify-instance-cpu-options \
    --instance-id 1234567890abcdef0 \
    --core-count=4 \
    --threads-per-core=2

Example 2: Disable simultaneous multi-threading by changing the number of threads that run per core to1. The resulting configuration also runs a total of 8 vCPUs (8 CPU cores with 1 thread per core).

aws ec2 modify-instance-cpu-options \
    --instance-id 1234567890abcdef0 \
    --core-count=8 \
    --threads-per-core=1

PowerShell

To change the number of active vCPUs for an instance

Use the Edit-EC2InstanceCpuOption cmdlet and specify the number of CPU cores that run in the -CoreCount parameter, and the number of threads that run per core in theThreadsPerCore parameter.

Example 1: Run 4 CPU cores with 2 threads per core, for a total of 8 vCPU.

Edit-EC2InstanceCpuOption `
    -InstanceId 'i-1234567890abcdef0' `
    -CoreCount 4 `
    -ThreadsPerCore 2

Example 2: Disable simultaneous multi-threading by changing the number of threads that run per core to1. The resulting configuration also runs a total of 8 vCPUs (8 CPU cores with 1 thread per core).

Edit-EC2InstanceCpuOption `
    -InstanceId 'i-1234567890abcdef0' `
    -CoreCount 8 `
    -ThreadsPerCore 1