Skip to content

Instantly share code, notes, and snippets.

@anuragmathur1
Created October 23, 2020 00:44
Show Gist options
  • Save anuragmathur1/062f562148351ef9b4705532f64586e8 to your computer and use it in GitHub Desktop.
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
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