Scalr\Service\Aws\Ec2\V20150415\Ec2Api::modifyInstanceAttribute PHP Method

modifyInstanceAttribute() public method

Modifies the specified attribute of the specified instance. You can specify only one attribute at a time. To modify some attributes, the instance must be stopped.
public modifyInstanceAttribute ( string $instanceId, Scalr\Service\Aws\Ec2\DataType\InstanceAttributeType $attribute, mixed $value ) : boolean
$instanceId string The ID of the Instance.
$attribute Scalr\Service\Aws\Ec2\DataType\InstanceAttributeType The attribute name.
$value mixed The attribute value can be string, boolean, array or object depends on attribute name.
return boolean Returns TRUE on success
    public function modifyInstanceAttribute($instanceId, InstanceAttributeType $attribute, $value)
    {
        $result = false;
        $options = ['InstanceId' => (string) $instanceId];
        $attribute = (string) $attribute;
        if (in_array($attribute, [InstanceAttributeType::TYPE_INSTANCE_TYPE, InstanceAttributeType::TYPE_KERNEL, InstanceAttributeType::TYPE_RAMDISK, InstanceAttributeType::TYPE_USER_DATA, InstanceAttributeType::TYPE_INSTANCE_INITIATED_SHUTDOWN_BEHAVIOR, InstanceAttributeType::TYPE_SRIOV_NET_SUPPORT])) {
            $options[ucfirst($attribute) . '.Value'] = (string) $value;
        } else {
            if (in_array($attribute, [InstanceAttributeType::TYPE_SOURCE_DEST_CHECK, InstanceAttributeType::TYPE_DISABLE_API_TERMINATION])) {
                $options[ucfirst($attribute) . '.Value'] = is_string($value) && ($value === 'true' || $value === 'false') ? $value : ($value ? 'true' : 'false');
            } else {
                if ($attribute == InstanceAttributeType::TYPE_BLOCK_DEVICE_MAPPING) {
                    if (!$value instanceof InstanceBlockDeviceMappingResponseList) {
                        $value = new InstanceBlockDeviceMappingResponseList($value);
                    }
                    $options = array_merge($options, $value->getQueryArrayBare('BlockDeviceMapping'));
                } else {
                    if ($attribute == InstanceAttributeType::TYPE_GROUP_SET) {
                        if (!$value instanceof ListDataType) {
                            $value = new ListDataType($value);
                        }
                        $options = array_merge($options, $value->getQueryArrayBare('GroupId'));
                    } else {
                        if ($attribute == InstanceAttributeType::TYPE_EBS_OPTIMIZED) {
                            $options['EbsOptimized'] = is_string($value) && ($value === 'true' || $value === 'false') ? $value : ($value ? 'true' : 'false');
                        } else {
                            throw new \BadFunctionCallException(sprintf('Unexpected attribute "%s" in the %s', $attribute, __FUNCTION__));
                        }
                    }
                }
            }
        }
        $action = ucfirst(__FUNCTION__);
        $response = $this->client->call($action, $options);
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            if ((string) $sxml->return != 'true') {
                throw new Ec2Exception(sprintf('Amazon Ec2 could not %s InstanceId:"%s". It returned "%s"', $action, $options['InstanceId'], $sxml->return));
            }
            $result = true;
        }
        return $result;
    }
Ec2Api