Sign in
agent:

Modify AWS EBS Volume type

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This runbook is a cost-effective and performance-optimized operational upgrade. In this case we see that GP3 volumes are less expensive than older types like GP2, while offering the ability to independently scale throughput and IOPS. This provides granular control over performance, reduces management overhead, and can lead to substantial cost savings. The conversion is typically straightforward and backward-compatible, making it an efficient way to modernize your AWS storage infrastructure.

  1. 1

    Filter out AWS EBS Volumes that are not GP3 type

    There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

    This task scans through your EBS volumes across different regions to flag those that are using older volume types like GP2. Knowing which volumes are not yet on GP3 allows you to target them for an upgrade, helping you take advantage of lower costs and improved performance features. This can be particularly useful for large organizations looking to streamline their AWS infrastructure and reduce operational costs.

    import boto3 from botocore.exceptions import ClientError creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def get_non_gp3_volumes(regions): """ Get the IDs of all EBS volumes that are not of type 'gp3'. Args: regions: List of AWS regions to check. Returns: Dictionary where the key is the region and the value is a list of non-GP3 volume IDs in that region. """ non_gp3_volumes_by_region = {} # Initialize dictionary to hold non-GP3 volumes by region for region in regions: try: # Initialize EC2 resource for the region ec2 = boto3.resource('ec2',aws_access_key_id=access_key,aws_secret_access_key=secret_key, region_name=region) # Initialize list to hold non-GP3 volumes for the region non_gp3_volumes = [] # Loop through all volumes in the region for volume in ec2.volumes.all(): if volume.volume_type != 'gp3': # Check if the volume is not of type 'gp3' non_gp3_volumes.append(volume.id) # Add volume ID to the list # If non-GP3 volumes are found in the current region, add them to the dictionary if non_gp3_volumes: non_gp3_volumes_by_region[region] = non_gp3_volumes print(f"Found {len(non_gp3_volumes)} non-GP3 volumes in {region}.") else: print(f"No non-GP3 volumes found in {region}.") except ClientError as e: print(f"A botocore exception occurred in region {region}: {e.response['Error']['Message']}") except Exception as e: print(f"An unknown error occurred in region {region}: {e}") return non_gp3_volumes_by_region # Define AWS regions to check #regions_to_check = ['us-east-1', 'us-west-2'] # Get non-GP3 volumes non_gp3_volumes_by_region = get_non_gp3_volumes(regions=regions_to_check) # Print the result print("Summary of non-GP3 volumes by region:") for region, volume_ids in non_gp3_volumes_by_region.items(): print(f"{region}: {volume_ids}") context.skip_sub_tasks = True
    copied
    1
    1. 1.1

      Change AWS EBS Volumes to GP3 type

      There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

      This task involves converting older volume types like GP2 and others to GP3. The transition to GP3 can result in cost savings and potentially improved performance, as GP3 volumes offer better throughput and the same baseline performance at a lower cost per GB. This operation is essential for organizations looking to modernize their storage infrastructure and optimize cloud expenses.

      import boto3 from botocore.exceptions import ClientError creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def modify_volumes_to_gp3(non_gp3_volumes_by_region): """ Modify EBS volumes to GP3 type. Args: non_gp3_volumes_by_region: Dictionary where the key is the region and the value is a list of non-GP3 volume IDs in that region. Returns: None """ # Loop through each region in the dictionary for region, volume_ids in non_gp3_volumes_by_region.items(): print(f"Checking region {region}...") # Initialize an EC2 client for the specific region ec2_client = boto3.client('ec2', aws_access_key_id=access_key,aws_secret_access_key=secret_key,region_name=region) # If there are non-GP3 volumes in the region, proceed to modify them if volume_ids: print(f"Found {len(volume_ids)} non-GP3 volumes in region {region}. Modifying them to GP3...") for volume_id in volume_ids: try: # Modify the volume to GP3 ec2_client.modify_volume( VolumeId=volume_id, VolumeType= ebs_volume_type ) print(f"Successfully modified volume {volume_id} to GP3 type in region {region}.") except ClientError as e: print(f"An error occurred while modifying volume {volume_id} in region {region}: {e.response['Error']['Message']}") else: print(f"No non-GP3 volumes found in region {region}.") ''' # Dictionary containing non-GP3 volume IDs, keyed by region non_gp3_volumes_by_region = { 'us-east-1': ['vol-0ae92bb63cdc04a67'] } ''' # Modify the non-GP3 volumes to GP3 type if non_gp3_volumes_by_region: modify_volumes_to_gp3(non_gp3_volumes_by_region) else: print("No non-GP3 volumes found.")
      copied
      1.1