Created
December 1, 2022 23:42
-
-
Save jdmedeiros/fe028c0f816fd8714859f31a77d63622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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