Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Sequential Execution EC2

import time
import boto3

class VolumesSequential(object):
    """Finds total volume size for all EC2 instances"""
    def __init__(self):
        self.ec2 = boto3.resource('ec2')

    def instance_volumes(self, instance):
        """
        Finds total size of the EBS volumes attached
        to an EC2 instance
        """
        instance_total = 0
        for volume in instance.volumes.all():
            instance_total += volume.size
        return instance_total

    def total_size(self):
        """
        Lists all EC2 instances in the default region
        and sums result of instance_volumes
        """
        print "Running sequentially"
        instances = self.ec2.instances.all()
        instances_total = 0
        for instance in instances:
            instances_total += self.instance_volumes(instance)
        return instances_total

def lambda_handler(event, context):
    volumes = VolumesSequential()
    _start = time.time()
    total = volumes.total_size()
    print "Total volume size: %s GB" % total
    print "Sequential execution time: %s seconds" % (time.time() - _start)
Comment

PREVIOUS NEXT
Code Example
Python :: dict keys in tcl 
Python :: CHECK POLYGON IS VALID 
Python :: using glob module to search all html files in current directory in python 
Python :: transfer learning in python with custom dataset 
Python :: python new set 
Python :: how to write together string type value and int type value in print function in python 
Python :: find not in dafatrame series 
Python :: Python NumPy atleast_3d Function Syntax 
Python :: Python NumPy moveaxis function Example 
Python :: python antigravity 
Python :: youtube-dl python not found 
Python :: Python NumPy asarray Function Example list to array 
Python :: Python NumPy require Function Example with requirements attribute 
Python :: advanced python code copy and paste 
Python :: How can Clone or Duplicate a Row Using np.tile 
Python :: if statment with logical or operator for multiple varaibles 
Python :: Python how to use __ne__ 
Python :: python service linux 
Python :: NumPy bitwise_or Code When inputs are arrays 
Python :: drop column 0 to many 
Python :: simple tower of hanoi project python with gui 
Python :: get primary key in get_context_data 
Python :: run server localhost for shar file 
Python :: python get dataframe vlaues where cell is higher than 
Python :: write an empty block python 
Python :: how to end if else statement in python 
Python :: How to correctly call url_for and specify path parameters 
Python :: edgar python documentation 
Python :: how to scrape data from github api python 
Python :: easy ocr python pypi 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =