Skip to content

create_instances_from_snapshot

create_instances_from_snapshot(
    instance_names: StringList,
    availability_zone: string,
    bundle_id: NonEmptyString,
    *,
    config_overrides: Optional[LightsailClientConfig] = None,
    attached_disk_mapping: Optional[AttachedDiskMap] = None,
    instance_snapshot_name: Optional[ResourceName] = None,
    user_data: Optional[string] = None,
    key_pair_name: Optional[ResourceName] = None,
    tags: Optional[TagList] = None,
    add_ons: Optional[AddOnRequestList] = None,
    ip_address_type: Optional[IpAddressType] = None,
    source_instance_name: Optional[string] = None,
    restore_date: Optional[string] = None,
    use_latest_restorable_auto_snapshot: Optional[boolean] = None,
) -> CreateInstancesFromSnapshotResult

Creates one or more new instances from a manual or automatic snapshot of an instance.

The create instances from snapshot operation supports tag-based access control via request tags and resource tags applied to the resource identified by instance snapshot name. For more information, see the Amazon Lightsail Developer Guide.

Parameters:

  • instance_names (StringList) –

    The names for your new instances.

  • attached_disk_mapping (Optional[AttachedDiskMap], default: None ) –

    An object containing information about one or more disk mappings.

  • availability_zone (string) –

    The Availability Zone where you want to create your instances. Use the following formatting: us-east-2a (case sensitive). You can get a list of Availability Zones by using the get regions operation. Be sure to add the include Availability Zones parameter to your request.

  • instance_snapshot_name (Optional[ResourceName], default: None ) –

    The name of the instance snapshot on which you are basing your new instances. Use the get instance snapshots operation to return information about your existing snapshots.

    Constraint:

    • This parameter cannot be defined together with the source instance name parameter. The instance snapshot name and source instance name parameters are mutually exclusive.

  • bundle_id (NonEmptyString) –

    The bundle of specification information for your virtual private server (or instance), including the pricing plan (micro_x_x).

  • user_data (Optional[string], default: None ) –

    You can create a launch script that configures a server with additional user data. For example, apt-get -y update.

    Depending on the machine image you choose, the command to get software on your instance varies. Amazon Linux and CentOS use yum, Debian and Ubuntu use apt-get, and FreeBSD uses pkg. For a complete list, see the Amazon Lightsail Developer Guide.

  • key_pair_name (Optional[ResourceName], default: None ) –

    The name for your key pair.

  • tags (Optional[TagList], default: None ) –

    The tag keys and optional values to add to the resource during create.

    Use the TagResource action to tag a resource after it's created.

  • add_ons (Optional[AddOnRequestList], default: None ) –

    An array of objects representing the add-ons to enable for the new instance.

  • ip_address_type (Optional[IpAddressType], default: None ) –

    The IP address type for the instance.

    The possible values are ipv4 for IPv4 only, ipv6 for IPv6 only, and dualstack for IPv4 and IPv6.

    The default value is dualstack.

  • source_instance_name (Optional[string], default: None ) –

    The name of the source instance from which the source automatic snapshot was created.

    Constraints:

    • This parameter cannot be defined together with the instance snapshot name parameter. The source instance name and instance snapshot name parameters are mutually exclusive.

    • Define this parameter only when creating a new instance from an automatic snapshot. For more information, see the Amazon Lightsail Developer Guide.

  • restore_date (Optional[string], default: None ) –

    The date of the automatic snapshot to use for the new instance. Use the get auto snapshots operation to identify the dates of the available automatic snapshots.

    Constraints:

    • Must be specified in YYYY-MM-DD format.

    • This parameter cannot be defined together with the use latest restorable auto snapshot parameter. The restore date and use latest restorable auto snapshot parameters are mutually exclusive.

    • Define this parameter only when creating a new instance from an automatic snapshot. For more information, see the Amazon Lightsail Developer Guide.

  • use_latest_restorable_auto_snapshot (Optional[boolean], default: None ) –

    A Boolean value to indicate whether to use the latest available automatic snapshot.

    Constraints:

    • This parameter cannot be defined together with the restore date parameter. The use latest restorable auto snapshot and restore date parameters are mutually exclusive.

    • Define this parameter only when creating a new instance from an automatic snapshot. For more information, see the Amazon Lightsail Developer Guide.

Raises:

  • AccessDeniedException –

    Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.

  • AccountSetupInProgressException –

    Lightsail throws this exception when an account is still in the setup in progress state.

  • InvalidInputException –

    Lightsail throws this exception when user input does not conform to the validation rules of an input field.

    Domain and distribution APIs are only available in the N. Virginia (us-east-1) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to us-east-1 to create, view, or edit these resources.

  • NotFoundException –

    Lightsail throws this exception when it cannot find a resource.

  • OperationFailureException –

    Lightsail throws this exception when an operation fails to execute.

  • RegionSetupInProgressException –

    Lightsail throws this exception when an operation is performed on resources in an opt-in Region that is currently being set up.

  • ServiceException –

    A general service exception.

  • UnauthenticatedException –

    Lightsail throws this exception when the user has not been authenticated.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_lightsail/_services/lightsail.py
def create_instances_from_snapshot(
    self,
    instance_names: "capo_lightsail.types.string_list.StringList",
    availability_zone: "capo_lightsail.types.string.string",
    bundle_id: "capo_lightsail.types.non_empty_string.NonEmptyString",
    *,
    config_overrides: Optional[LightsailClientConfig] = None,
    attached_disk_mapping: Optional[
        "capo_lightsail.types.attached_disk_map.AttachedDiskMap"
    ] = None,
    instance_snapshot_name: Optional[
        "capo_lightsail.types.resource_name.ResourceName"
    ] = None,
    user_data: Optional["capo_lightsail.types.string.string"] = None,
    key_pair_name: Optional[
        "capo_lightsail.types.resource_name.ResourceName"
    ] = None,
    tags: Optional["capo_lightsail.types.tag_list.TagList"] = None,
    add_ons: Optional[
        "capo_lightsail.types.add_on_request_list.AddOnRequestList"
    ] = None,
    ip_address_type: Optional[
        "capo_lightsail.types.ip_address_type.IpAddressType"
    ] = None,
    source_instance_name: Optional["capo_lightsail.types.string.string"] = None,
    restore_date: Optional["capo_lightsail.types.string.string"] = None,
    use_latest_restorable_auto_snapshot: Optional[
        "capo_lightsail.types.boolean.boolean"
    ] = None,
) -> "capo_lightsail.types.create_instances_from_snapshot_result.CreateInstancesFromSnapshotResult":
    """<p>Creates one or more new instances from a manual or automatic snapshot of an instance.</p> <p>The <code>create instances from snapshot</code> operation supports tag-based access control via request tags and resource tags applied to the resource identified by <code>instance snapshot name</code>. For more information, see the <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags">Amazon Lightsail Developer Guide</a>.</p>

    Args:
        instance_names: <p>The names for your new instances.</p>
        attached_disk_mapping: <p>An object containing information about one or more disk mappings.</p>
        availability_zone: <p>The Availability Zone where you want to create your instances. Use the following formatting: <code>us-east-2a</code> (case sensitive). You can get a list of Availability Zones by using the <a href="http://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetRegions.html">get regions</a> operation. Be sure to add the <code>include Availability Zones</code> parameter to your request.</p>
        instance_snapshot_name: <p>The name of the instance snapshot on which you are basing your new instances. Use the get instance snapshots operation to return information about your existing snapshots.</p> <p>Constraint:</p> <ul> <li> <p>This parameter cannot be defined together with the <code>source instance name</code> parameter. The <code>instance snapshot name</code> and <code>source instance name</code> parameters are mutually exclusive.</p> </li> </ul>
        bundle_id: <p>The bundle of specification information for your virtual private server (or <i>instance</i>), including the pricing plan (<code>micro_x_x</code>).</p>
        user_data: <p>You can create a launch script that configures a server with additional user data. For example, <code>apt-get -y update</code>.</p> <note> <p>Depending on the machine image you choose, the command to get software on your instance varies. Amazon Linux and CentOS use <code>yum</code>, Debian and Ubuntu use <code>apt-get</code>, and FreeBSD uses <code>pkg</code>. For a complete list, see the <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/compare-options-choose-lightsail-instance-image">Amazon Lightsail Developer Guide</a>.</p> </note>
        key_pair_name: <p>The name for your key pair.</p>
        tags: <p>The tag keys and optional values to add to the resource during create.</p> <p>Use the <code>TagResource</code> action to tag a resource after it's created.</p>
        add_ons: <p>An array of objects representing the add-ons to enable for the new instance.</p>
        ip_address_type: <p>The IP address type for the instance.</p> <p>The possible values are <code>ipv4</code> for IPv4 only, <code>ipv6</code> for IPv6 only, and <code>dualstack</code> for IPv4 and IPv6.</p> <p>The default value is <code>dualstack</code>.</p>
        source_instance_name: <p>The name of the source instance from which the source automatic snapshot was created.</p> <p>Constraints:</p> <ul> <li> <p>This parameter cannot be defined together with the <code>instance snapshot name</code> parameter. The <code>source instance name</code> and <code>instance snapshot name</code> parameters are mutually exclusive.</p> </li> <li> <p>Define this parameter only when creating a new instance from an automatic snapshot. For more information, see the <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots">Amazon Lightsail Developer Guide</a>.</p> </li> </ul>
        restore_date: <p>The date of the automatic snapshot to use for the new instance. Use the <code>get auto snapshots</code> operation to identify the dates of the available automatic snapshots.</p> <p>Constraints:</p> <ul> <li> <p>Must be specified in <code>YYYY-MM-DD</code> format.</p> </li> <li> <p>This parameter cannot be defined together with the <code>use latest restorable auto snapshot</code> parameter. The <code>restore date</code> and <code>use latest restorable auto snapshot</code> parameters are mutually exclusive.</p> </li> <li> <p>Define this parameter only when creating a new instance from an automatic snapshot. For more information, see the <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots">Amazon Lightsail Developer Guide</a>.</p> </li> </ul>
        use_latest_restorable_auto_snapshot: <p>A Boolean value to indicate whether to use the latest available automatic snapshot.</p> <p>Constraints:</p> <ul> <li> <p>This parameter cannot be defined together with the <code>restore date</code> parameter. The <code>use latest restorable auto snapshot</code> and <code>restore date</code> parameters are mutually exclusive.</p> </li> <li> <p>Define this parameter only when creating a new instance from an automatic snapshot. For more information, see the <a href="https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-configuring-automatic-snapshots">Amazon Lightsail Developer Guide</a>.</p> </li> </ul>

    Raises:
        capo_lightsail.errors.access_denied_exception.AccessDeniedException: <p>Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.</p>
        capo_lightsail.errors.account_setup_in_progress_exception.AccountSetupInProgressException: <p>Lightsail throws this exception when an account is still in the setup in progress state.</p>
        capo_lightsail.errors.invalid_input_exception.InvalidInputException: <p>Lightsail throws this exception when user input does not conform to the validation rules of an input field.</p> <note> <p>Domain and distribution APIs are only available in the N. Virginia (<code>us-east-1</code>) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to <code>us-east-1</code> to create, view, or edit these resources.</p> </note>
        capo_lightsail.errors.not_found_exception.NotFoundException: <p>Lightsail throws this exception when it cannot find a resource.</p>
        capo_lightsail.errors.operation_failure_exception.OperationFailureException: <p>Lightsail throws this exception when an operation fails to execute.</p>
        capo_lightsail.errors.region_setup_in_progress_exception.RegionSetupInProgressException: <p>Lightsail throws this exception when an operation is performed on resources in an opt-in Region that is currently being set up.</p>
        capo_lightsail.errors.service_exception.ServiceException: <p>A general service exception.</p>
        capo_lightsail.errors.unauthenticated_exception.UnauthenticatedException: <p>Lightsail throws this exception when the user has not been authenticated.</p>
        capo_lightsail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_lightsail.types.create_instances_from_snapshot_request.CreateInstancesFromSnapshotRequest]",
    ) -> OperationResponse[
        "capo_lightsail.types.create_instances_from_snapshot_result.CreateInstancesFromSnapshotResult"
    ]:
        import capo_lightsail._operations.lightsail_20161128.create_instances_from_snapshot

        output, http_response = (
            capo_lightsail._operations.lightsail_20161128.create_instances_from_snapshot.create_instances_from_snapshot(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateInstancesFromSnapshot")
    )
    input_: capo_lightsail.types.create_instances_from_snapshot_request.CreateInstancesFromSnapshotRequest = {
        "instance_names": instance_names,
        "availability_zone": availability_zone,
        "bundle_id": bundle_id,
    }
    if attached_disk_mapping is not None:
        input_["attached_disk_mapping"] = attached_disk_mapping
    if instance_snapshot_name is not None:
        input_["instance_snapshot_name"] = instance_snapshot_name
    if user_data is not None:
        input_["user_data"] = user_data
    if key_pair_name is not None:
        input_["key_pair_name"] = key_pair_name
    if tags is not None:
        input_["tags"] = tags
    if add_ons is not None:
        input_["add_ons"] = add_ons
    if ip_address_type is not None:
        input_["ip_address_type"] = ip_address_type
    if source_instance_name is not None:
        input_["source_instance_name"] = source_instance_name
    if restore_date is not None:
        input_["restore_date"] = restore_date
    if use_latest_restorable_auto_snapshot is not None:
        input_["use_latest_restorable_auto_snapshot"] = (
            use_latest_restorable_auto_snapshot
        )

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output