Last active
January 4, 2022 06:47
-
-
Save tomofuminijo/a90b049a0af425aa5b018f3847f21284 to your computer and use it in GitHub Desktop.
Increase the disk size on Cloud9 instance
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
pip3 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