Created
October 23, 2020 00:44
-
-
Save anuragmathur1/062f562148351ef9b4705532f64586e8 to your computer and use it in GitHub Desktop.
Increase volume and Reboot the instance. You can, however, do without rebooting as well with some additional steps
This file contains 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
pip install --user --upgrade boto3 | |
export instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
python -c "import boto3 | |
import os | |
from botocore.exceptions import ClientError | |
ec2 = boto3.client('ec2') | |
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=30 | |
) | |
print(resize) | |
except ClientError as e: | |
if e.response['Error']['Code'] == 'InvalidParameterValue': | |
print('ERROR MESSAGE: {}'.format(e))" | |
if [ $? -eq 0 ]; then | |
sudo reboot | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment