Net::Amazon::EC2(3pm)

๐Ÿ“ฆ
version 0.36 ยท 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– Net::Amazon::EC2(3pm) ๐Ÿ’–

okay bestie, welcome to Net::Amazon::EC2 from the User Contributed Perl Documentation collection. This is the Perl interface to Amazon's Elastic Compute Cloud (EC2), and we're about to make it make sense. ๐Ÿฆ‹


โœจ NAME โœจ

Net::Amazon::EC2 โ€” Perl interface to the Amazon Elastic Compute Cloud (EC2) environment. ๐Ÿ’…

โญ VERSION โญ

EC2 Query API version: '2014-06-15'

๐Ÿ’– SYNOPSIS ๐Ÿ’–

        use Net::Amazon::EC2;

        my $ec2 = Net::Amazon::EC2->new(
               AWSAccessKeyId    => 'PUBLIC_KEY_HERE',
               SecretAccessKey   => 'SECRET_KEY_HERE',
               signature_version => 4,
        );

        # Start 1 new instance from AMI: ami-XXXXXXXX
        my $instance = $ec2->run_instances(ImageId => 'ami-XXXXXXXX', MinCount => 1, MaxCount => 1);

        my $running_instances = $ec2->describe_instances;

        foreach my $reservation (@$running_instances) {
               foreach my $instance ($reservation->instances_set) {
                       print $instance->instance_id . "\n";
               }
        }

        my $instance_id = $instance->instances_set->[0]->instance_id;

        print "$instance_id\n";

        # Terminate instance

        my $result = $ec2->terminate_instances(InstanceId => $instance_id);

If an error occurs while communicating with EC2, these methods will throw a Net::Amazon::EC2::Errors exception. ๐Ÿ˜ญ

๐ŸŒธ DESCRIPTION ๐ŸŒธ

This module is a Perl interface to Amazon's Elastic Compute Cloud. It uses the Query API to communicate with Amazon's Web Services framework. fr fr, that's the whole plot. โœจ

๐ŸŽ€ CLASS METHODS ๐ŸŽ€

new(%params)

This is the constructor, bestie โ€” it returns you a Net::Amazon::EC2 object to work with. It takes these parameters:

  • AWSAccessKeyId โ€” required, unless an IAM role is present. Your AWS access key. For info on IAM roles, see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UsingIAM.html#UsingIAMrolesWithAmazonEC2Instances.
  • SecretAccessKey โ€” required, unless an IAM role is present. Your secret key. WARNING! don't give this out or someone will be able to use your account and incur charges on your behalf. ๐Ÿšจ
  • SecurityToken โ€” optional. When using temporary credentials from STS, the Security Token must be passed in along with the temporary AWSAccessKeyId and SecretAccessKey. The most common case is when using IAM credentials with the addition of MFA (multi-factor authentication). See http://docs.aws.amazon.com/STS/latest/UsingSTS/Welcome.html.
  • region โ€” optional. The region to run the API requests through. Defaults to us-east-1.
  • ssl โ€” optional. If set to a true value, the base_url will use https:// instead of http://. Setting base_url explicitly will override this. Defaults to true as of 0.22.
  • debug โ€” optional. A flag to turn on debugging. Among other useful things, it will make the failing api calls print a stack trace. It is turned off by default.
  • return_errors โ€” optional. Previously, Net::Amazon::EC2 would return a Net::Amazon::EC2::Errors object when it encountered an error condition. As of 0.19, this object is thrown as an exception using croak or confess depending on if the debug flag is set. If you want/need the old behavior, set this attribute to a true value.

๐Ÿฆ‹ OBJECT METHODS ๐Ÿฆ‹

allocate_address()

Acquires an elastic IP address which can be associated with an EC2-classic instance to create a movable static IP. Takes no arguments. Returns the IP address obtained. ๐Ÿ’…

allocate_vpc_address()

Acquires an elastic IP address which can be associated with a VPC instance to create a movable static IP. Takes no arguments. Returns the allocationId of the allocated address.

associate_address(%params)

Associates an elastic IP address with an instance. It takes the following arguments:

  • InstanceId โ€” required. The instance id you wish to associate the IP address with.
  • PublicIp โ€” optional. The IP address. Used for allocating addresses to EC2-classic instances.
  • AllocationId โ€” optional. The allocation ID. Used for allocating address to VPC instances.

Returns true if the association succeeded. โœจ

attach_volume(%params)

Attach a volume to an instance. ๐Ÿงš

  • VolumeId โ€” required. The volume id you wish to attach.
  • InstanceId โ€” required. The instance id you wish to attach the volume to.
  • Device โ€” required. The device id you want the volume attached as.

Returns a Net::Amazon::EC2::Attachment object containing the resulting volume status.

authorize_security_group_ingress(%params)

This method adds permissions to a security group. It takes the following parameters:

  • GroupName โ€” required. The name of the group to add security rules to.
  • SourceSecurityGroupName โ€” required when authorizing a user and group together. Name of the group to add access for.
  • SourceSecurityGroupOwnerId โ€” required when authorizing a user and group together. Owner of the group to add access for.
  • IpProtocol โ€” required when adding access for a CIDR. IP Protocol of the rule you are adding access for (TCP, UDP, or ICMP).
  • FromPort โ€” required when adding access for a CIDR. Beginning of port range to add access for.
  • ToPort โ€” required when adding access for a CIDR. End of port range to add access for.
  • CidrIp โ€” required when adding access for a CIDR. The CIDR IP space we are adding access for.

Adding a rule can be done in two ways: adding a source group name + source group owner id, or, CIDR IP range. Both methods allow IP protocol, from port and to port specifications.

Returns 1 if rule is added successfully.

bundle_instance(%params)

Bundles the Windows instance. This procedure is not applicable for Linux and UNIX instances.

NOTE NOTE NOTE This is not well tested as I don't run windows instances. ๐Ÿ˜ญ
  • InstanceId โ€” required. The ID of the instance to bundle.
  • Storage.S3.Bucket โ€” required. The bucket in which to store the AMI. You can specify a bucket that you already own or a new bucket that Amazon EC2 creates on your behalf. If you specify a bucket that belongs to someone else, Amazon EC2 returns an error.
  • Storage.S3.Prefix โ€” required. Specifies the beginning of the file name of the AMI.
  • Storage.S3.AWSAccessKeyId โ€” required. The Access Key ID of the owner of the Amazon S3 bucket.
  • Storage.S3.UploadPolicy โ€” required. An Amazon S3 upload policy that gives Amazon EC2 permission to upload items into Amazon S3 on the user's behalf.
  • Storage.S3.UploadPolicySignature โ€” required. The signature of the Base64 encoded JSON document.

JSON Parameters: (all are required)

  • expiration โ€” The expiration of the policy. Amazon recommends 12 hours or longer.
  • conditions โ€” A list of restrictions on what can be uploaded to Amazon S3. Must contain the bucket and ACL conditions in this table.
  • bucket โ€” The bucket to store the AMI.
  • acl โ€” This must be set to ec2-bundle-read.

Returns a Net::Amazon::EC2::BundleInstanceResponse object.

cancel_bundle_task(%params)

Cancels the bundle task. This procedure is not applicable for Linux and UNIX instances.

  • BundleId โ€” required. The ID of the bundle task to cancel.

Returns a Net::Amazon::EC2::BundleInstanceResponse object.

confirm_product_instance(%params)

Checks to see if the product code passed in is attached to the instance id, taking the following parameter:

  • ProductCode โ€” required. The Product Code to check.
  • InstanceId โ€” required. The Instance Id to check.

Returns a Net::Amazon::EC2::ConfirmProductInstanceResponse object.

create_image(%params)

Creates an AMI that uses an Amazon EBS root device from a "running" or "stopped" instance.

AMIs that use an Amazon EBS root device boot faster than AMIs that use instance stores. They can be up to 1 TiB in size, use storage that persists on instance failure, and can be stopped and started.

  • InstanceId โ€” required. The ID of the instance.
  • Name โ€” required. The name of the AMI that was provided during image creation.

Note that the image name has the following constraints:

3-128 alphanumeric characters, parenthesis, commas, slashes, dashes, or underscores.

  • Description โ€” optional. The description of the AMI that was provided during image creation.
  • NoReboot โ€” optional. By default this property is set to false, which means Amazon EC2 attempts to cleanly shut down the instance before image creation and reboots the instance afterwards. When set to true, Amazon EC2 does not shut down the instance before creating the image. When this option is used, file system integrity on the created image cannot be guaranteed. โš ๏ธ
  • BlockDeviceMapping โ€” optional. Array ref of the device names exposed to the instance.

You can specify device names as '<device>=<block_device>' similar to ec2-create-image command. (http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CreateImage.html)

             BlockDeviceMapping => [
                   '/dev/sda=:256:true:standard',
                   '/dev/sdb=none',
                   '/dev/sdc=ephemeral0',
                   '/dev/sdd=ephemeral1',
             ],

Returns the ID of the AMI created.

create_key_pair(%params)

Creates a new 2048 bit key pair, taking the following parameter:

  • KeyName โ€” required. A name for this key. Should be unique.

Returns a Net::Amazon::EC2::KeyPair object.

create_security_group(%params)

This method creates a new security group. It takes the following parameters:

  • GroupName โ€” required. The name of the new group to create.
  • GroupDescription โ€” required. A short description of the new group.

Returns 1 if the group creation succeeds.

create_snapshot(%params)

Create a snapshot of a volume. It takes the following arguments:

  • VolumeId โ€” required. The volume id of the volume you want to take a snapshot of.
  • Description โ€” optional. Description of the Amazon EBS snapshot.

Returns a Net::Amazon::EC2::Snapshot object of the newly created snapshot.

create_tags(%params)

Creates tags. ๐Ÿท๏ธ

  • ResourceId โ€” required. The ID of the resource to create tags. Can be a scalar or arrayref.
  • Tags โ€” required. Hashref where keys and values will be set on all resources given in the first element.

Returns true if the tag creation succeeded.

create_volume(%params)

Creates a volume.

  • Size โ€” required. The size in GiB ( 1024^3 ) of the volume you want to create.
  • SnapshotId โ€” optional. The optional snapshot id to create the volume from. The volume must be equal or larger than the snapshot it was created from.
  • AvailabilityZone โ€” required. The availability zone to create the volume in.
  • VolumeType โ€” optional. The volume type: 'standard', 'gp2', or 'io1'. Defaults to 'standard'.

Iops (required if VolumeType is 'io1')

The number of I/O operations per second (IOPS) that the volume supports. It's capped at 30 times the volume size, with an absolute max of 4000. And bestie, those numbers are very likely to change in the future, so don't hardcode them in your soul.

Required when the volume type is io1; not used otherwise. Like, if you're not on io1, this field is just sitting there uninvited. ๐Ÿ’€

Encrypted (optional)

Encrypt the volume. EBS encrypted volumes get encrypted on the host using AWS managed keys. Only some instance types support encrypted volumes. And at the time of writing โ€” this is a real caveat, pay attention โ€” encrypted volumes are not supported for boot volumes. ๐Ÿ˜ญ

Returns a Net::Amazon::EC2::Volume object containing the resulting volume status.


delete_key_pair(%params)

Deletes a keypair. Slay, goodbye keypair. Takes this one parameter:

  • KeyName (required) โ€” the name of the key you're yeeting.

Returns 1 if the key was successfully deleted. ๐ŸŽ€

delete_security_group(%params)

Deletes a security group. Takes this parameter:

  • GroupName (required) โ€” the name of the security group you want gone.

Returns 1 if the delete succeeded.

delete_snapshot(%params)

Deletes the snapshots you pass in. Arguments:

  • SnapshotId (required) โ€” pass in a snapshot id and the corresponding snapshot gets deleted. Periodt.

Returns true if the deleting succeeded.

delete_volume(%params)

Delete a volume. Simple as that.

  • VolumeId (required) โ€” the volume id you wish to delete.

Returns true if the deleting succeeded.

delete_tags(%params)

Delete tags. Untagging is self-care. ๐Ÿ’…

  • ResourceId (required) โ€” the ID of the resource to delete tags from.
  • Tag.Key (required) โ€” key for a tag, may pass in a scalar or arrayref.
  • Tag.Value (required) โ€” value for a tag, may pass in a scalar or arrayref.

Returns true if the releasing succeeded.

deregister_image(%params)

This one deregisters an AMI. Takes this parameter:

  • ImageId (required) โ€” the image id of the AMI you want to deregister.

Returns 1 if the deregistering succeeded. ๐Ÿ‘‘

describe_addresses(%params)

Describes the elastic addresses currently allocated, plus any instances associated with them. Arguments:

  • PublicIp (optional) โ€” the IP address to describe. Can be either a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::DescribeAddress objects.

describe_availability_zones(%params)

Describes the availability zones you currently have to choose from. Arguments:

  • ZoneName (optional) โ€” the zone name to describe. Can be either a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::AvailabilityZone objects.

describe_bundle_tasks(%params)

Describes current bundling tasks. Heads up: this procedure is not applicable for Linux and UNIX instances. ๐Ÿšซ

  • BundleId (optional) โ€” the optional ID of the bundle task to describe.

Returns an array ref of Net::Amazon::EC2::BundleInstanceResponse objects.

describe_image_attributes(%params)

Pulls a list of attributes for the image id you specify.

  • ImageId (required) โ€” a scalar containing the image you want the list of attributes for.
  • Attribute (required) โ€” a scalar containing the attribute to describe.

Valid attributes are:

  • launchPermission โ€” the AMIs launch permissions.
  • ImageId โ€” ID of the AMI for which an attribute will be described.
  • productCodes โ€” the product code attached to the AMI.
  • kernel โ€” describes the ID of the kernel associated with the AMI.
  • ramdisk โ€” describes the ID of RAM disk associated with the AMI.
  • blockDeviceMapping โ€” defines native device names to use when exposing virtual devices.
  • platform โ€” describes the operating system platform.

Returns a Net::Amazon::EC2::DescribeImageAttribute object.

โš ๏ธ NOTE: There is currently a bug in Amazon's SOAP and Query API โ€” when you try to describe the attributes kernel, ramdisk, blockDeviceMapping, or platform, AWS returns an invalid response. No response yet from Amazon on an ETA for getting that bug fixed. So likeโ€ฆ not our fault, not our problem, but definitely our problem. ๐Ÿ’€

describe_images(%params)

Pulls a list of the AMIs that can be run. You can narrow that list down by passing in some of these parameters:

  • ImageId (optional) โ€” either a scalar or an array ref; passing it means just these AMIs get 'described'.
  • Owner (optional) โ€” either a scalar or an array ref; passing it means AMIs owned by the Owner(s) you provide get 'described'. Pass either account ids, or 'amazon' for all amazon-owned AMIs, or 'self' for your own AMIs.
  • ExecutableBy (optional) โ€” either a scalar or an array ref; passing it means AMIs executable by the account id(s) specified get 'described'. Or 'self' for your own AMIs.

Returns an array ref of Net::Amazon::EC2::DescribeImagesResponse objects.

describe_instances(%params)

Pulls a list of the instances which are running, or which were just running. Narrow it down with these:

  • InstanceId (optional) โ€” either a scalar or an array ref; passing it means just these instances get 'described'.
  • Filter (optional) โ€” the filters so only matching instances get 'described'. A filter tuple is an arrayref consisting of one key and one or more values. This option takes one filter tuple, or an arrayref of multiple filter tuples.

Returns an array ref of Net::Amazon::EC2::ReservationInfo objects.

describe_instance_status(%params)

Pulls a list of instances based on some status filter. Modify the list with these:

  • InstanceId (optional) โ€” either a scalar or an array ref; passing it means just these instances get 'described'.
  • Filter (optional) โ€” the filters so only matching instances get 'described'. A filter tuple is an arrayref consisting of one key and one or more values. This option takes one filter tuple, or an arrayref of multiple filter tuples.

Returns an array ref of Net::Amazon::EC2::InstanceStatuses objects.

_create_describe_instance_status(%instanceElement)

Returns a blessed object. Used internally for wrapping describe_instance_status nextToken calls โ€” so like, that leading underscore? Yeah, that's the "do not touch, this is backstage" underscore. ๐Ÿ™ˆ

  • InstanceStatusElement (required) โ€” the instance status element we want to build out and return.

Returns a Net::Amazon::EC2::InstanceStatuses object.

describe_instance_attribute(%params)

Returns info about an attribute of an instance. Only one attribute can be specified per call โ€” no bundling, bestie, one at a time. โœจ

  • InstanceId (required) โ€” the instance id whose attributes we want to describe.
  • Attribute (required) โ€” the attribute we want to describe. Valid values are:
    • instanceType
    • kernel
    • ramdisk
    • userData
    • disableApiTermination
    • ebsOptimized
    • instanceInitiatedShutdownBehavior
    • rootDeviceName
    • sourceDestCheck
    • blockDeviceMapping

Returns a Net::Amazon::EC2::DescribeInstanceAttributeResponse object.

describe_key_pairs(%params)

Describes the keypairs available on this account. Takes this parameter:

  • KeyName (optional) โ€” the name of the key to be described. Can be either a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::DescribeKeyPairsResponse objects.

describe_regions(%params)

Describes the EC2 regions that are currently available to launch instances in for this account. ๐ŸŒ

  • RegionName (optional) โ€” the name of the region(s) to be described. Can be either a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::Region objects.

describe_reserved_instances(%params)

Describes the Reserved Instances that you purchased. Look at you, planning ahead. ๐Ÿ‘‘

  • ReservedInstancesId (optional) โ€” the reserved instance id(s) to be described. Can be either a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::ReservedInstance objects.

describe_reserved_instances_offerings(%params)

Describes the Reserved Instance offerings that are available for purchase. With Amazon EC2 Reserved Instances, you purchase the right to launch Amazon EC2 instances for a period of time โ€” and the whole point is you do it without getting insufficient capacity errors, plus you pay a lower usage rate for the actual time used. It's giving "pay now, vibe later". ๐Ÿ’ธ

  • ReservedInstancesOfferingId (optional) โ€” ID of the Reserved Instances to describe.
  • InstanceType (optional) โ€” the instance type. The default is m1.small. Amazon frequently updates their instance types. See http://aws.amazon.com/ec2/instance-types
  • AvailabilityZone (optional) โ€” the Availability Zone in which the Reserved Instance can be used.
  • ProductDescription (optional) โ€” the Reserved Instance description.

Returns an array ref of Net::Amazon::EC2::ReservedInstanceOffering objects.

describe_security_groups(%params)

Describes the security groups available to this account. Takes these parameters:

  • GroupName (optional) โ€” the name of the security group(s) to be described. Can be either a scalar or an array ref.
  • GroupId (optional) โ€” the id of the security group(s) to be described. Can be either a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::SecurityGroup objects.

describe_snapshot_attribute(%params)

Describes the snapshot attributes related to the snapshot in question. Arguments:

  • SnapshotId (optional) โ€” either a scalar or an array ref of snapshot id's. If this isn't passed in, it will describe the attributes of all the current snapshots.
  • Attribute (required) โ€” the attribute to describe. Currently the only valid attribute is createVolumePermission.

Returns a Net::Amazon::EC2::SnapshotAttribute object.

describe_snapshots(%params)

Describes the snapshots available to the user. Arguments:

  • SnapshotId (optional) โ€” either a scalar or an array ref of snapshot id's. If this isn't passed in, it will describe all the current snapshots.
  • Owner (optional) โ€” the owner of the snapshot.
  • RestorableBy (optional) โ€” a user who can create volumes from the snapshot.
  • Filter (optional) โ€” the filters so only matching snapshots get 'described'. A filter tuple is an arrayref consisting of one key and one or more values. This option takes one filter tuple, or an arrayref of multiple filter tuples.

Returns an array ref of Net::Amazon::EC2::Snapshot objects.

describe_volumes(%params)

Describes the volumes currently created. It takes the following arguments:

  • VolumeId (optional) โ€” drop in either a single scalar or an array ref of volume ids. Skip it entirely and it'll just describe every volume you've got rn. ๐Ÿ’…

Returns an array ref of Net::Amazon::EC2::Volume objects.


๐ŸŒˆ describe_subnets(%params) ๐ŸŒˆ

This one spills the tea on the subnets chilling in this account. Params it wants:

  • SubnetId (optional) โ€” the id of the subnet you wanna describe. Scalar or array ref, dealer's choice. โœจ
  • Filter.Name (optional) โ€” the name of the Filter.Name to be described. Can be a scalar or an array ref. Peep http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html for the filters that actually exist, iykyk.
  • Filter.Value (optional) โ€” the name of the Filter.Value to be described. Scalar or array ref, either one. ๐Ÿฆ‹

Returns an array ref of Net::Amazon::EC2::DescribeSubnetResponse objects.


๐ŸŽ€ describe_tags(%params) ๐ŸŽ€

Describes the tags available on this account. Just one param bestie:

  • Filter.Name (optional) โ€” the name of the Filter.Name to be described. Scalar or array ref, you pick.
  • Filter.Value (optional) โ€” the name of the Filter.Value to be described. Scalar or array ref, no cap.

Returns an array ref of Net::Amazon::EC2::DescribeTags objects.


๐Ÿ’… detach_volume(%params) ๐Ÿ’…

Detach a volume from an instance. It's giving "we're breaking up." ๐Ÿ˜ญ

  • VolumeId (required) โ€” the volume id you wish to detach.
  • InstanceId (optional) โ€” the instance id you wish to detach from.
  • Device (optional) โ€” the device the volume was attached as.
  • Force (optional) โ€” a boolean for if to forcibly detach the volume from the instance.
โš ๏ธ WARNING: This can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. โš ๏ธ

Returns a Net::Amazon::EC2::Attachment object containing the resulting volume status.


๐ŸŒธ disassociate_address(%params) ๐ŸŒธ

Disassociates an elastic IP address with an instance. It takes the following arguments:

  • PublicIp (conditional) โ€” the IP address to disassociate, mandatory to remove an IP from a EC2-classic instance.
  • AssociationId (conditional) โ€” the Association ID of an IP address, mandatory to remove an IP from a VPC instance.

Returns true if the disassociation succeeded. ๐Ÿซถ


โญ get_console_output(%params) โญ

Gets the output from the virtual console for an instance. Params:

  • InstanceId (required) โ€” a scalar containing a instance id.

Returns a Net::Amazon::EC2::ConsoleOutput object or "undef" if there is no new output. (This can happen in cases where the console output has not changed since the last call.) ๐Ÿ’€


๐Ÿ‘‘ get_password_data(%params) ๐Ÿ‘‘

Retrieves the encrypted administrator password for the instances running Windows. Heads up: this procedure is not applicable for Linux and UNIX instances. ๐Ÿ™ˆ

  • InstanceId (required) โ€” the Instance Id for which to retrieve the password.

Returns a Net::Amazon::EC2::InstancePassword object.


โœจ modify_image_attribute(%params) โœจ

Modifies attributes of an machine image. Main character energy fr.

  • ImageId (required) โ€” the AMI to modify the attributes of.
  • Attribute (required) โ€” the attribute you wish to modify. Right now the attributes you can modify are launchPermission and productCodes.
  • OperationType (required for launchPermission) โ€” the operation you wish to perform on the attribute. Right now just 'add' and 'remove' are supported.
  • UserId (required for launchPermission) โ€” user Id's you wish to add/remove from the attribute.
  • UserGroup (required for launchPermission) โ€” groups you wish to add/remove from the attribute. Currently there is only one User Group available: 'all' for all Amazon EC2 customers.
  • ProductCode (required for productCodes) โ€” attaches a product code to the AMI. Currently only one product code can be assigned to the AMI. Once this is set it cannot be changed or reset. ๐Ÿ”’

Returns 1 if the modification succeeds.


๐Ÿ’œ modify_instance_attribute(%params) ๐Ÿ’œ

Modify an attribute of an instance. So specific, love that for us.

  • InstanceId (required) โ€” the instance id we want to modify the attributes of.
  • Attribute (required) โ€” the attribute we want to modify. Valid values are:
    • instanceType
    • kernel
    • ramdisk
    • userData
    • disableApiTermination
    • instanceInitiatedShutdownBehavior
    • rootDeviceName
    • blockDeviceMapping
  • Value (required) โ€” the value to set the attribute to.

You may also pass a hashref with one or more keys and values. This hashref will be flattened and passed to AWS.

For example:

$ec2->modify_instance_attribute(
        'InstanceId' => $id,
        'Attribute' => 'blockDeviceMapping',
        'Value' => {
                'BlockDeviceMapping.1.DeviceName' => '/dev/sdf1',
                'BlockDeviceMapping.1.Ebs.DeleteOnTermination' => 'true',
        }
);

Returns 1 if the modification succeeds.


๐Ÿงš modify_snapshot_attribute(%params) ๐Ÿงš

Modifies attributes of a snapshot. Snapshot glow-up โœจ

  • SnapshotId (required) โ€” the snapshot id to modify the attributes of.
  • UserId (optional) โ€” user Id you wish to add/remove create volume permissions for.
  • UserGroup (optional) โ€” user Id you wish to add/remove create volume permissions for. To make the snapshot createable by all set the UserGroup to "all".
  • Attribute (required) โ€” the attribute you wish to modify. Right now the only attribute you can modify is "CreateVolumePermission".
  • OperationType (required) โ€” the operation you wish to perform on the attribute. Right now just 'add' and 'remove' are supported.

Returns 1 if the modification succeeds.


๐Ÿ”ฅ monitor_instances(%params) ๐Ÿ”ฅ

Enables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide. ๐Ÿ‘€

  • InstanceId (required) โ€” the instance id(s) to monitor. Can be a scalar or an array ref.

Returns an array ref of Net::Amazon::EC2::MonitoredInstance objects.


๐ŸŒˆ purchase_reserved_instances_offering(%params) ๐ŸŒˆ

Purchases a Reserved Instance for use with your account. With Amazon EC2 Reserved Instances, you purchase the right to launch Amazon EC2 instances for a period of time (without getting insufficient capacity errors) and pay a lower usage rate for the actual time used. It's literally the subscription plan of AWS. ๐Ÿ’ธ

  • ReservedInstancesOfferingId (required) โ€” ID of the Reserved Instances to describe. Can be either a scalar or an array ref.
  • InstanceCount (optional) โ€” the number of Reserved Instances to purchase (default is 1). Can be either a scalar or an array ref.
๐Ÿ“ข NOTE NOTE NOTE, the array ref needs to line up with the InstanceCount if you want to pass that in, so that the right number of instances are started of the right instance offering. Don't play yourself bestie. ๐Ÿ˜ญ

Returns 1 if the reservations succeeded.


๐ŸŽ€ reboot_instances(%params) ๐ŸŽ€

Reboots an instance. Have you tried turning it off and on again ๐Ÿ’…

  • InstanceId (required) โ€” instance Id of the instance you wish to reboot. Can be either a scalar or array ref of instances to reboot.

Returns 1 if the reboot succeeded.


๐Ÿฆ‹ register_image(%params) ๐Ÿฆ‹

Registers an AMI on the EC2. Params:

  • ImageLocation (optional) โ€” the location of the AMI manifest on S3.
  • Name (required) โ€” the name of the AMI that was provided during image creation.
  • Description (optional) โ€” the description of the AMI.
  • Architecture (optional) โ€” the architecture of the image. Either i386 or x86_64.
  • KernelId (optional) โ€” the ID of the kernel to select.
  • RamdiskId (optional) โ€” the ID of the RAM disk to select. Some kernels require additional drivers at launch.
  • RootDeviceName (optional) โ€” the root device name (e.g., /dev/sda1).
  • BlockDeviceMapping (optional) โ€” this needs to be a data structure like this:
[
        {
                deviceName      => "/dev/sdh", (optional)
                virtualName     => "ephemerel0", (optional)
                noDevice        => "/dev/sdl", (optional),
                ebs                     => {
                        snapshotId                      => "snap-0000", (optional)
                        volumeSize                      => "20", (optional)
                        deleteOnTermination     => "false", (optional)
                },
        },
        ...
]

Returns the image id of the new image on EC2. ๐Ÿ‘‘


โญ release_address(%params) โญ

Releases an allocated IP address. It takes the following arguments:

  • PublicIp (required) โ€” the IP address to release.

Returns true if the releasing succeeded. Bye bye IP ๐Ÿซถ


๐Ÿ’œ reset_image_attribute(%params) ๐Ÿ’œ

Resets an attribute for an AMI to its default state (NOTE: product codes cannot be reset). Params:

  • ImageId (required) โ€” the image id of the AMI you wish to reset the attributes on.
  • Attribute (required) โ€” the attribute you want to reset.

Returns 1 if the attribute reset succeeds.


โœจ reset_instance_attribute(%params) โœจ

Reset an attribute of an instance. Only one attribute can be specified per call, so don't get greedy. ๐Ÿ™ˆ

  • InstanceId (required) โ€” the instance id we want to reset the attributes of.
  • Attribute (required) โ€” the attribute we want to reset. Valid values are:
    • kernel
    • ramdisk

Returns 1 if the reset succeeds.


๐ŸŒธ reset_snapshot_attribute(%params) ๐ŸŒธ

Resets an attribute for an snapshot to its default state. It takes the following parameters:

  • SnapshotId (required) โ€” the snapshot id of the snapshot you wish to reset the attributes on.
  • Attribute (required) โ€” the attribute you want to reset (currently "CreateVolumePermission" is the only valid attribute).

Returns 1 if the attribute reset succeeds.


๐Ÿ”ฅ revoke_security_group_ingress(%params) ๐Ÿ”ฅ

Revokes permissions to a security group. It takes the following parameters:

  • GroupName (required) โ€” the name of the group to revoke security rules from.
  • SourceSecurityGroupName (required when revoking a user and group together) โ€” name of the group to revoke access from.
  • SourceSecurityGroupOwnerId (required when revoking a user and group together) โ€” owner of the group to revoke access from.
  • IpProtocol (required when revoking access from a CIDR) โ€” the IP protocol of the rule you're revoking access from. It's giving TCP, UDP, or ICMP ๐Ÿ’…
  • FromPort (required when revoking access from a CIDR) โ€” where the port range starts for the access you're revoking. ๐ŸŽ€
  • ToPort (required when revoking access from a CIDR) โ€” where the port range ends for the access you're revoking. โœจ
  • CidrIp (required when revoking access from a CIDR) โ€” the CIDR IP space you're revoking access from. ๐ŸŒธ

Revoking a rule can be done in two ways: revoking a source group name + source group owner id, or, by Protocol + start port + end port + CIDR IP. The two are mutually exclusive. ๐Ÿ‘‘

Returns 1 if rule is revoked successfully. โœ…


๐Ÿš€ run_instances(%params) ๐Ÿš€

okay so this method starts instance(s) of AMIs on EC2. The params tell it which AMI to spin up and how many / what properties they have:

  • ImageId (required) โ€” the image id you want to start an instance of. ๐Ÿ–ผ๏ธ
  • MinCount (required) โ€” the minimum number of instances to start. ๐Ÿ”ข
  • MaxCount (required) โ€” the maximum number of instances to start. ๐Ÿ”ข
  • KeyName (optional) โ€” the keypair name to associate this instance with. If omitted, it'll use your default keypair. ๐Ÿ”‘
  • SecurityGroup (optional) โ€” a scalar or array ref. Will associate this instance with the group names passed in. If omitted, it'll be associated with the default security group. ๐Ÿ›ก๏ธ
  • SecurityGroupId (optional) โ€” a scalar or array ref. Will associate this instance with the group ids passed in. If omitted, it'll be associated with the default security group. ๐Ÿ›ก๏ธ
  • AdditionalInfo (optional) โ€” specifies additional information to make available to the instance(s). ๐Ÿ“
  • UserData (optional) โ€” optional data to pass into the instance being started. Needs to be base64 encoded. ๐Ÿ”
  • InstanceType (optional) โ€” specifies the type of instance to start. See http://aws.amazon.com/ec2/instance-types for the full vibe. The options are:
    • m1.small (default) โ€” 1 EC2 Compute Unit (1 virtual core with 1 EC2 Compute Unit). 32-bit or 64-bit, 1.7GB RAM, 160GB disk ๐Ÿ“
    • m1.medium Medium Instance โ€” 2 EC2 Compute Units (1 virtual core with 2 EC2 Compute Unit), 32-bit or 64-bit, 3.75GB RAM, 410GB disk ๐Ÿ’–
    • m1.large: Standard Large Instance โ€” 4 EC2 Compute Units (2 virtual cores with 2 EC2 Compute Units each). 64-bit, 7.5GB RAM, 850GB disk โœจ
    • m1.xlarge: Standard Extra Large Instance โ€” 8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units each). 64-bit, 15GB RAM, 1690GB disk ๐Ÿ’ซ
    • t1.micro Micro Instance โ€” Up to 2 EC2 Compute Units (for short periodic bursts), 32-bit or 64-bit, 613MB RAM, EBS storage only ๐Ÿœ
    • c1.medium: High-CPU Medium Instance โ€” 5 EC2 Compute Units (2 virtual cores with 2.5 EC2 Compute Units each). 32-bit or 64-bit, 1.7GB RAM, 350GB disk ๐Ÿ”ฅ
    • c1.xlarge: High-CPU Extra Large Instance โ€” 20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each). 64-bit, 7GB RAM, 1690GB disk ๐Ÿ”ฅ
    • m2.2xlarge High-Memory Double Extra Large Instance โ€” 13 EC2 Compute Units (4 virtual cores with 3.25 EC2 Compute Units each). 64-bit, 34.2GB RAM, 850GB disk ๐Ÿง 
    • m2.4xlarge High-Memory Quadruple Extra Large Instance โ€” 26 EC2 Compute Units (8 virtual cores with 3.25 EC2 Compute Units each). 64-bit, 68.4GB RAM, 1690GB disk ๐Ÿง 
    • cc1.4xlarge Cluster Compute Quadruple Extra Large Instance โ€” 33.5 EC2 Compute Units (2 x Intel Xeon X5570, quad-core "Nehalem" architecture), 64-bit, 23GB RAM, 1690GB disk, 10Gbit Ethernet ๐Ÿ–ฅ๏ธ
    • cc1.8xlarge Cluster Compute Eight Extra Large Instance โ€” 88 EC2 Compute Units (2 x Intel Xeon E5-2670, eight-core "Sandy Bridge" architecture), 64-bit, 60.5GB RAM, 3370GB disk, 10Gbit Ethernet ๐Ÿ–ฅ๏ธ
    • cg1.4xlarge Cluster GPU Quadruple Extra Large Instance โ€” 33.5 EC2 Compute Units (2 x Intel Xeon X5570, quad-core "Nehalem" architecture), 64-bit, 22GB RAM 1690GB disk, 10Gbit Ethernet, 2 x NVIDIA Tesla "Fermi" M2050 GPUs ๐ŸŽฎ
    • hi1.4xlarge High I/O Quadruple Extra Large Instance โ€” 35 EC2 Compute Units (16 virtual cores), 60.5GB RAM, 64-bit, 2 x 1024GB SSD disk, 10Gbit Ethernet โšก
  • Placement.AvailabilityZone (optional) โ€” the availability zone you want to run the instance in. ๐ŸŒ
  • KernelId (optional) โ€” the id of the kernel you want to launch the instance with. ๐Ÿง 
  • RamdiskId (optional) โ€” the id of the ramdisk you want to launch the instance with. ๐Ÿ’พ
  • BlockDeviceMapping.VirtualName (optional) โ€” this is the virtual name for a blocked device to be attached, may pass in a scalar or arrayref. ๐Ÿ“€
  • BlockDeviceMapping.DeviceName (optional) โ€” this is the device name for a block device to be attached, may pass in a scalar or arrayref. ๐Ÿ’ฝ
  • BlockDeviceMapping.Ebs.VolumeSize (optional) โ€” specifies the size of the root block device as an integer (GB). If used, required that BlockDeviceMapping.DeviceName also be specified. One may pass in a scalar or arrayref. This parameter will override the disk size settings implied by the InstanceType, if used. ๐Ÿ“

Additional volume related parameters include:

  • BlockDeviceMapping.Ebs.SnapshotId โ€” May pass in a scalar or arrayref. ๐Ÿ“ธ
  • BlockDeviceMapping.Ebs.VolumeType โ€” May pass in a scalar or arrayref. ๐Ÿ—‚๏ธ
  • BlockDeviceMapping.Ebs.DeleteOnTermination โ€” May pass in a scalar or arrayref. ๐Ÿ—‘๏ธ
  • Encoding (optional) โ€” the encoding. ๐Ÿ”ค
  • Version (optional) โ€” the version. ๐Ÿ”ข
  • Monitoring.Enabled (optional) โ€” enables monitoring for this instance. ๐Ÿ‘€
  • SubnetId (optional) โ€” specifies the subnet ID within which to launch the instance(s) for Amazon Virtual Private Cloud. ๐ŸŒ
  • ClientToken (optional) โ€” specifies the idempotent instance id. ๐ŸŽŸ๏ธ
  • EbsOptimized (optional) โ€” whether the instance is optimized for EBS I/O. โšก
  • PrivateIpAddress (optional) โ€” specifies the private IP address to use when launching an Amazon VPC instance. ๐Ÿ 
  • IamInstanceProfile.Name (optional) โ€” specifies the IAM profile to associate with the launched instance(s). This is the name of the role. ๐Ÿ‘ค
  • IamInstanceProfile.Arn (optional) โ€” specifies the IAM profile to associate with the launched instance(s). This is the ARN of the profile. ๐Ÿ†”

Returns a Net::Amazon::EC2::ReservationInfo object. ๐Ÿ“ฆ


๐ŸŸข start_instances(%params) ๐ŸŸข

Starts an instance that uses an Amazon EBS volume as its root device. ๐Ÿ’ฝ

  • InstanceId (required) โ€” Either a scalar or an array ref can be passed in (containing instance ids to be started). ๐Ÿ†”

Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects. ๐Ÿ”„


โน๏ธ stop_instances(%params) โน๏ธ

Stops an instance that uses an Amazon EBS volume as its root device. ๐Ÿ’ฝ

  • InstanceId (required) โ€” Either a scalar or an array ref can be passed in (containing instance ids to be stopped). ๐Ÿ†”
  • Force (optional) โ€” If set to true, forces the instance to stop. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures. This option is not recommended for Windows instances. ๐Ÿšจ

The default is false. โŒ

Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects. ๐Ÿ”„


๐Ÿ’€ terminate_instances(%params) ๐Ÿ’€

This method shuts down instance(s) passed into it. It takes the following parameter:

  • InstanceId (required) โ€” Either a scalar or an array ref can be passed in (containing instance ids). ๐Ÿ†”

Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects. ๐Ÿ”„


๐Ÿ™ˆ unmonitor_instances(%params) ๐Ÿ™ˆ

Disables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide. ๐Ÿ“‰

  • InstanceId (required) โ€” The instance id(s) to monitor. Can be a scalar or an array ref. ๐Ÿ†”

Returns an array ref of Net::Amazon::EC2::MonitoredInstance objects. ๐Ÿ“Š


โœจ TESTING โœจ

Set AWS_ACCESS_KEY_ID and SECRET_ACCESS_KEY environment variables to run the live tests. ๐Ÿ”‘ Note: because the live tests start an instance (and kill it) in both the tests and backwards compat tests there will be 2 hours of machine instance usage charges (since there are 2 instances started) which as of February 1st, 2010 costs a total of $0.17 USD ๐Ÿ’ธ

Important note about the windows-only methods. These have not been well tested as I do not run windows-based instances, so exercise caution in using these. โš ๏ธ


๐Ÿ› BUGS ๐Ÿ›

Please report any bugs or feature requests to bug-net-amazon-ec2 at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Amazon-EC2. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. ๐Ÿซถ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Jeff Kim cpan@chosec.com ๐Ÿ’–


๐ŸŒŸ CONTRIBUTORS ๐ŸŒŸ

John McCullough and others as listed in the Changelog ๐Ÿ“œ


๐Ÿ› ๏ธ MAINTAINER ๐Ÿ› ๏ธ

The current maintainer is Mark Allen "<mallen@cpan.org>" ๐Ÿ’…


Copyright (c) 2006-2010 Jeff Kim. ๐Ÿ“†

Copyright (c) 2012 Mark Allen. ๐Ÿ“†

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. ๐Ÿช


๐Ÿ”— SEE ALSO ๐Ÿ”—

Amazon EC2 API: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ โ˜๏ธ


This page was served fresh by perl v5.36.0 on 2022-12-06, and it's Net::Amazon::EC2(3pm). Stay slaying, bestie ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from