Skip to content

Instantly share code, notes, and snippets.

@jdmedeiros
Created December 1, 2022 23:42
Show Gist options
  • Save jdmedeiros/fe028c0f816fd8714859f31a77d63622 to your computer and use it in GitHub Desktop.
Save jdmedeiros/fe028c0f816fd8714859f31a77d63622 to your computer and use it in GitHub Desktop.
# Make sure to export the instance ID
# export instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
import boto3
import os
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2', region_name='us-east-1')
volume_info = ec2.describe_volumes(
Filters=[
{
'Name': 'attachment.instance-id',
'Values': [
os.getenv('instance_id')
]
}
]
)
volume_id = volume_info['Volumes'][0]['VolumeId']
try:
resize = ec2.modify_volume(
VolumeId=volume_id,
Size=40
)
print(resize)
except ClientError as e:
if e.response['Error']['Code'] == 'InvalidParameterValue':
print('ERROR MESSAGE: {}'.format(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment