EC2 / Client / run_scheduled_instances

run_scheduled_instances#

EC2.Client.run_scheduled_instances(**kwargs)#

Launches the specified Scheduled Instances.

Before you can launch a Scheduled Instance, you must purchase it and obtain an identifier using PurchaseScheduledInstances.

You must launch a Scheduled Instance during its scheduled time period. You can’t stop or reboot a Scheduled Instance, but you can terminate it as needed. If you terminate a Scheduled Instance before the current scheduled time period ends, you can launch it again after a few minutes. For more information, see Scheduled Instances in the Amazon EC2 User Guide.

See also: AWS API Documentation

Request Syntax

response = client.run_scheduled_instances(
    ClientToken='string',
    DryRun=True|False,
    InstanceCount=123,
    LaunchSpecification={
        'BlockDeviceMappings': [
            {
                'DeviceName': 'string',
                'Ebs': {
                    'DeleteOnTermination': True|False,
                    'Encrypted': True|False,
                    'Iops': 123,
                    'SnapshotId': 'string',
                    'VolumeSize': 123,
                    'VolumeType': 'string'
                },
                'NoDevice': 'string',
                'VirtualName': 'string'
            },
        ],
        'EbsOptimized': True|False,
        'IamInstanceProfile': {
            'Arn': 'string',
            'Name': 'string'
        },
        'ImageId': 'string',
        'InstanceType': 'string',
        'KernelId': 'string',
        'KeyName': 'string',
        'Monitoring': {
            'Enabled': True|False
        },
        'NetworkInterfaces': [
            {
                'AssociatePublicIpAddress': True|False,
                'DeleteOnTermination': True|False,
                'Description': 'string',
                'DeviceIndex': 123,
                'Groups': [
                    'string',
                ],
                'Ipv6AddressCount': 123,
                'Ipv6Addresses': [
                    {
                        'Ipv6Address': 'string'
                    },
                ],
                'NetworkInterfaceId': 'string',
                'PrivateIpAddress': 'string',
                'PrivateIpAddressConfigs': [
                    {
                        'Primary': True|False,
                        'PrivateIpAddress': 'string'
                    },
                ],
                'SecondaryPrivateIpAddressCount': 123,
                'SubnetId': 'string'
            },
        ],
        'Placement': {
            'AvailabilityZone': 'string',
            'GroupName': 'string'
        },
        'RamdiskId': 'string',
        'SecurityGroupIds': [
            'string',
        ],
        'SubnetId': 'string',
        'UserData': 'string'
    },
    ScheduledInstanceId='string'
)
Parameters:
  • ClientToken (string) –

    Unique, case-sensitive identifier that ensures the idempotency of the request. For more information, see Ensuring Idempotency.

    This field is autopopulated if not provided.

  • DryRun (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 is UnauthorizedOperation.

  • InstanceCount (integer) –

    The number of instances.

    Default: 1

  • LaunchSpecification (dict) –

    [REQUIRED]

    The launch specification. You must match the instance type, Availability Zone, network, and platform of the schedule that you purchased.

    • BlockDeviceMappings (list) –

      The block device mapping entries.

      • (dict) –

        Describes a block device mapping for a Scheduled Instance.

        • DeviceName (string) –

          The device name (for example, /dev/sdh or xvdh).

        • Ebs (dict) –

          Parameters used to set up EBS volumes automatically when the instance is launched.

          • DeleteOnTermination (boolean) –

            Indicates whether the volume is deleted on instance termination.

          • Encrypted (boolean) –

            Indicates whether the volume is encrypted. You can attached encrypted volumes only to instances that support them.

          • Iops (integer) –

            The number of I/O operations per second (IOPS) to provision for a gp3, io1, or io2 volume.

          • SnapshotId (string) –

            The ID of the snapshot.

          • VolumeSize (integer) –

            The size of the volume, in GiB.

            Default: If you’re creating the volume from a snapshot and don’t specify a volume size, the default is the snapshot size.

          • VolumeType (string) –

            The volume type.

            Default: gp2

        • NoDevice (string) –

          To omit the device from the block device mapping, specify an empty string.

        • VirtualName (string) –

          The virtual device name ( ephemeral``N). Instance store volumes are numbered starting from 0. An instance type with two available instance store volumes can specify mappings for ``ephemeral0 and ephemeral1. The number of available instance store volumes depends on the instance type. After you connect to the instance, you must mount the volume.

          Constraints: For M3 instances, you must specify instance store volumes in the block device mapping for the instance. When you launch an M3 instance, we ignore any instance store volumes specified in the block device mapping for the AMI.

    • EbsOptimized (boolean) –

      Indicates whether the instances are optimized for 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.

      Default: false

    • IamInstanceProfile (dict) –

      The IAM instance profile.

      • Arn (string) –

        The Amazon Resource Name (ARN).

      • Name (string) –

        The name.

    • ImageId (string) – [REQUIRED]

      The ID of the Amazon Machine Image (AMI).

    • InstanceType (string) –

      The instance type.

    • KernelId (string) –

      The ID of the kernel.

    • KeyName (string) –

      The name of the key pair.

    • Monitoring (dict) –

      Enable or disable monitoring for the instances.

      • Enabled (boolean) –

        Indicates whether monitoring is enabled.

    • NetworkInterfaces (list) –

      The network interfaces.

      • (dict) –

        Describes a network interface for a Scheduled Instance.

        • AssociatePublicIpAddress (boolean) –

          Indicates whether to assign a public IPv4 address to instances launched in a VPC. The public IPv4 address can only be assigned to a network interface for eth0, and can only be assigned to a new network interface, not an existing one. You cannot specify more than one network interface in the request. If launching into a default subnet, the default value is true.

          Amazon Web Services charges for all public IPv4 addresses, including public IPv4 addresses associated with running instances and Elastic IP addresses. For more information, see the Public IPv4 Address tab on the Amazon VPC pricing page.

        • DeleteOnTermination (boolean) –

          Indicates whether to delete the interface when the instance is terminated.

        • Description (string) –

          The description.

        • DeviceIndex (integer) –

          The index of the device for the network interface attachment.

        • Groups (list) –

          The IDs of the security groups.

          • (string) –

        • Ipv6AddressCount (integer) –

          The number of IPv6 addresses to assign to the network interface. The IPv6 addresses are automatically selected from the subnet range.

        • Ipv6Addresses (list) –

          The specific IPv6 addresses from the subnet range.

          • (dict) –

            Describes an IPv6 address.

            • Ipv6Address (string) –

              The IPv6 address.

        • NetworkInterfaceId (string) –

          The ID of the network interface.

        • PrivateIpAddress (string) –

          The IPv4 address of the network interface within the subnet.

        • PrivateIpAddressConfigs (list) –

          The private IPv4 addresses.

          • (dict) –

            Describes a private IPv4 address for a Scheduled Instance.

            • Primary (boolean) –

              Indicates whether this is a primary IPv4 address. Otherwise, this is a secondary IPv4 address.

            • PrivateIpAddress (string) –

              The IPv4 address.

        • SecondaryPrivateIpAddressCount (integer) –

          The number of secondary private IPv4 addresses.

        • SubnetId (string) –

          The ID of the subnet.

    • Placement (dict) –

      The placement information.

      • AvailabilityZone (string) –

        The Availability Zone.

      • GroupName (string) –

        The name of the placement group.

    • RamdiskId (string) –

      The ID of the RAM disk.

    • SecurityGroupIds (list) –

      The IDs of the security groups.

      • (string) –

    • SubnetId (string) –

      The ID of the subnet in which to launch the instances.

    • UserData (string) –

      The base64-encoded MIME user data.

  • ScheduledInstanceId (string) –

    [REQUIRED]

    The Scheduled Instance ID.

Return type:

dict

Returns:

Response Syntax

{
    'InstanceIdSet': [
        'string',
    ]
}

Response Structure

  • (dict) –

    Contains the output of RunScheduledInstances.

    • InstanceIdSet (list) –

      The IDs of the newly launched instances.

      • (string) –

Examples

This example launches the specified Scheduled Instance in a VPC.

response = client.run_scheduled_instances(
    InstanceCount=1,
    LaunchSpecification={
        'IamInstanceProfile': {
            'Name': 'my-iam-role',
        },
        'ImageId': 'ami-12345678',
        'InstanceType': 'c4.large',
        'KeyName': 'my-key-pair',
        'NetworkInterfaces': [
            {
                'AssociatePublicIpAddress': True,
                'DeviceIndex': 0,
                'Groups': [
                    'sg-12345678',
                ],
                'SubnetId': 'subnet-12345678',
            },
        ],
    },
    ScheduledInstanceId='sci-1234-1234-1234-1234-123456789012',
)

print(response)

Expected Output:

{
    'InstanceIdSet': [
        'i-1234567890abcdef0',
    ],
    'ResponseMetadata': {
        '...': '...',
    },
}

This example launches the specified Scheduled Instance in EC2-Classic.

response = client.run_scheduled_instances(
    InstanceCount=1,
    LaunchSpecification={
        'IamInstanceProfile': {
            'Name': 'my-iam-role',
        },
        'ImageId': 'ami-12345678',
        'InstanceType': 'c4.large',
        'KeyName': 'my-key-pair',
        'Placement': {
            'AvailabilityZone': 'us-west-2b',
        },
        'SecurityGroupIds': [
            'sg-12345678',
        ],
    },
    ScheduledInstanceId='sci-1234-1234-1234-1234-123456789012',
)

print(response)

Expected Output:

{
    'InstanceIdSet': [
        'i-1234567890abcdef0',
    ],
    'ResponseMetadata': {
        '...': '...',
    },
}