Modifies the specified attribute of the specified instance. You can specify only one attribute at a time.
Note: Using this action to change the security groups associated with an elastic network interface (ENI) attached to an instance in a VPC can result in an error if the instance has more than one ENI. To change the security groups associated with an ENI attached to an instance that has multiple ENIs, we recommend that you use the ModifyNetworkInterfaceAttribute action.
To modify some attributes, the instance must be stopped. For more information, see Modifying attributes of a stopped instance in the Amazon Elastic Compute Cloud User Guide .
See also: AWS API Documentation
See ‘aws help’ for descriptions of global parameters.
modify-instance-attribute
[--source-dest-check | --no-source-dest-check]
[--attribute <value>]
[--block-device-mappings <value>]
[--disable-api-termination | --no-disable-api-termination]
[--dry-run | --no-dry-run]
[--ebs-optimized | --no-ebs-optimized]
[--ena-support | --no-ena-support]
[--groups <value>]
--instance-id <value>
[--instance-initiated-shutdown-behavior <value>]
[--instance-type <value>]
[--kernel <value>]
[--ramdisk <value>]
[--sriov-net-support <value>]
[--user-data <value>]
[--value <value>]
[--cli-input-json | --cli-input-yaml]
[--generate-cli-skeleton <value>]
--source-dest-check
| --no-source-dest-check
(structure)
Specifies whether source/destination checking is enabled. A value of
true
means that checking is enabled, andfalse
means that checking is disabled. This value must befalse
for a NAT instance to perform NAT.Value -> (boolean)
The attribute value. The valid values are
true
orfalse
.
--attribute
(string)
The name of the attribute.
Possible values:
instanceType
kernel
ramdisk
userData
disableApiTermination
instanceInitiatedShutdownBehavior
rootDeviceName
blockDeviceMapping
productCodes
sourceDestCheck
groupSet
ebsOptimized
sriovNetSupport
enaSupport
enclaveOptions
--block-device-mappings
(list)
Modifies the
DeleteOnTermination
attribute for volumes that are currently attached. The volume must be owned by the caller. If no value is specified forDeleteOnTermination
, the default istrue
and the volume is deleted when the instance is terminated.To add instance store volumes to an Amazon EBS-backed instance, you must add them when you launch the instance. For more information, see Updating the block device mapping when launching an instance in the Amazon Elastic Compute Cloud User Guide .
(structure)
Describes a block device mapping entry.
DeviceName -> (string)
The device name (for example,
/dev/sdh
orxvdh
).Ebs -> (structure)
Parameters used to automatically set up EBS volumes when the instance is launched.
DeleteOnTermination -> (boolean)
Indicates whether the volume is deleted on instance termination.
VolumeId -> (string)
The ID of the EBS volume.
NoDevice -> (string)
suppress the specified device included in the block device mapping.
VirtualName -> (string)
The virtual device name.
Shorthand Syntax:
DeviceName=string,Ebs={DeleteOnTermination=boolean,VolumeId=string},NoDevice=string,VirtualName=string ...
JSON Syntax:
[
{
"DeviceName": "string",
"Ebs": {
"DeleteOnTermination": true|false,
"VolumeId": "string"
},
"NoDevice": "string",
"VirtualName": "string"
}
...
]
--disable-api-termination
| --no-disable-api-termination
(structure)
If the value is
true
, you can’t terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can. You cannot use this parameter for Spot Instances.Value -> (boolean)
The attribute value. The valid values are
true
orfalse
.
--dry-run
| --no-dry-run
(boolean)
Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is
DryRunOperation
. Otherwise, it isUnauthorizedOperation
.
--ebs-optimized
| --no-ebs-optimized
(structure)
Specifies whether the instance is optimized for Amazon EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal EBS I/O performance. This optimization isn’t available with all instance types. Additional usage charges apply when using an EBS Optimized instance.
Value -> (boolean)
The attribute value. The valid values are
true
orfalse
.
--ena-support
| --no-ena-support
(structure)
Set to
true
to enable enhanced networking with ENA for the instance.This option is supported only for HVM instances. Specifying this option with a PV instance can make it unreachable.
Value -> (boolean)
The attribute value. The valid values are
true
orfalse
.
--groups
(list)
[EC2-VPC] Changes the security groups of the instance. You must specify at least one security group, even if it’s just the default security group for the VPC. You must specify the security group ID, not the security group name.
(string)
Syntax:
"string" "string" ...
--instance-id
(string)
The ID of the instance.
--instance-initiated-shutdown-behavior
(structure)
Specifies whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).
Value -> (string)
The attribute value. The value is case-sensitive.
--instance-type
(structure)
Changes the instance type to the specified value. For more information, see Instance types . If the instance type is not valid, the error returned is
InvalidInstanceAttributeValue
.Value -> (string)
The attribute value. The value is case-sensitive.
--kernel
(structure)
Changes the instance’s kernel to the specified value. We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB .
Value -> (string)
The attribute value. The value is case-sensitive.
--ramdisk
(structure)
Changes the instance’s RAM disk to the specified value. We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB .
Value -> (string)
The attribute value. The value is case-sensitive.
--sriov-net-support
(structure)
Set to
simple
to enable enhanced networking with the Intel 82599 Virtual Function interface for the instance.There is no way to disable enhanced networking with the Intel 82599 Virtual Function interface at this time.
This option is supported only for HVM instances. Specifying this option with a PV instance can make it unreachable.
Value -> (string)
The attribute value. The value is case-sensitive.
--user-data
(structure)
Changes the instance’s user data to the specified value. If you are using an AWS SDK or command line tool, base64-encoding is performed for you, and you can load the text from a file. Otherwise, you must provide base64-encoded text.
Value -> (blob)
Shorthand Syntax:
Value=blob
JSON Syntax:
{
"Value": blob
}
--value
(string)
A new value for the attribute. Use only with the
kernel
,ramdisk
,userData
,disableApiTermination
, orinstanceInitiatedShutdownBehavior
attribute.
--cli-input-json
| --cli-input-yaml
(string)
Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton
. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml
.
--generate-cli-skeleton
(string)
Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input
, prints a sample input JSON that can be used as an argument for --cli-input-json
. Similarly, if provided yaml-input
it will print a sample input YAML that can be used with --cli-input-yaml
. If provided with the value output
, it validates the command inputs and returns a sample output JSON for that command.
See ‘aws help’ for descriptions of global parameters.
Example 1: To modify the instance type
The following modify-instance-attribute
example modifies the instance type of the specified instance. The instance must be in the stopped
state.
aws ec2 modify-instance-attribute \
--instance-id i-1234567890abcdef0 \
--instance-type "{\"Value\": \"m1.small\"}"
This command produces no output.
Example 2: To enable enhanced networking on an instance
The following modify-instance-attribute
example enables enhanced networking for the specified instance. The instance must be in the stopped
state.
aws ec2 modify-instance-attribute \
--instance-id i-1234567890abcdef0 \
--sriov-net-support simple
This command produces no output.
Example 3: To modify the sourceDestCheck attribute
The following modify-instance-attribute
example sets the sourceDestCheck
attribute of the specified instance to true
. The instance must be in a VPC.
aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --source-dest-check "{\"Value\": true}"
This command produces no output.
Example 4: To modify the deleteOnTermination attribute of the root volume
The following modify-instance-attribute
example sets the deleteOnTermination
attribute for the root volume of the specified Amazon EBS-backed instance to false
. By default, this attribute is true
for the root volume.
Command:
aws ec2 modify-instance-attribute \
--instance-id i-1234567890abcdef0 \
--block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]"
This command produces no output.
Example 5: To modify the user data attached to an instance
The following modify-instance-attribute
example adds the contents of the file UserData.txt
as the UserData for the specified instance.
Contents of original file UserData.txt
:
#!/bin/bash
yum update -y
service httpd start
chkconfig httpd on
The contents of the file must be base64 encoded. The first command converts the text file to base64 and saves it as a new file.
Linux/macOS version of the command:
base64 UserData.txt > UserData.base64.txt
This command produces no output.
Windows version of the command:
certutil -encode UserData.txt tmp.b64 && findstr /v /c:- tmp.b64 > UserData.base64.txt
Output:
Input Length = 67
Output Length = 152
CertUtil: -encode command completed successfully.
Now you can reference that file in the CLI command that follows:
aws ec2 modify-instance-attribute \
--instance-id=i-09b5a14dbca622e76 \
--attribute userData --value fileb://UserData.base64.txt
This command produces no output.
For more information, see User Data and the AWS CLI in the EC2 User Guide.
None