AWS Cloud9のディスクサイズを増やす

AWS Cloud9のディスクサイズを増やす:


はじめに

Amazon Web Services(AWS)のIDE(統合開発環境)サービスであるAWS Cloud9はブラウザで利用可能なクラウドIDEなんですが、環境を作成すると自分のアカウント内にEC2インスタンスを起動してそこにセットアップしてくれます。

Cloud9上のデータは基本的にそのインスタンスのルート(/)に保存されるのですがライブラリやらフレームワークやらインストールしているとこのボリュームが足りなくなってしまうケースがあります。

というわけでこれを増やします。ドキュメントも用意されていてとっても簡単です。

AWS Cloud9 で Environment を移動またはサイズ変更する

ではこれをやっていきましょう。


サイズ変更したいenvironmentを開く

要は増やしたいCloud9の環境を開くだけです。


以下のシェルスクリプトを作成する

開いた環境上で以下の内容のシェルスクリプトを作成します。ファイル名は適当でいいです。保存するのもどこでもいいと思いますが、ここでは/home/ec2-user/environment1resize.shという名前で用意します。

#!/bin/bash 
 
# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB. 
SIZE=${1:=20} 
 
# Install the jq command-line JSON processor. 
sudo yum -y install jq 
 
# Get the ID of the envrionment host Amazon EC2 instance. 
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data//instance-id) 
 
# Get the ID of the Amazon EBS volume associated with the instance. 
VOLUMEID=$(aws ec2 describe-instances --instance-id $INSTANCEID | jq -r .Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId) 
 
# Resize the EBS volume. 
aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE 
 
# Wait for the resize to finish. 
while [ "$(aws ec2 describe-volumes-modifications --volume-id $VOLUMEID --filters Name=modification-state,Values="optimizing","completed" | jq '.VolumesModifications | length')" != "1" ]; do 
  sleep 1 
done 
 
# Rewrite the partition table so that the partition takes up all the space that it can. 
sudo growpart /dev/xvda 1 
 
# Expand the size of the file system. 
sudo resize2fs /dev/xvda1 


スクリプトを実行する

以下のようにこのスクリプトを実行します。増やしたいサイズ(増加後のサイズ)をGBで指定します。ここでは思い切って50GBまで増やしたいと思います。

sh resize.sh 50 
実行するとこんな感じでツラツラーとメッセージが表示されて終わります。

Loaded plugins: priorities, update-motd, upgrade-helper 
amzn-main                                                                                                         | 2.1 kB  00:00:00      
amzn-updates                                                                                                      | 2.5 kB  00:00:00      
1060 packages excluded due to repository priority protections 
Resolving Dependencies 
--> Running transaction check 
---> Package jq.x86_64 0:1.5-1.2.amzn1 will be installed 
--> Processing Dependency: jq-libs(x86-64) = 1.5-1.2.amzn1 for package: jq-1.5-1.2.amzn1.x86_64 
--> Processing Dependency: oniguruma for package: jq-1.5-1.2.amzn1.x86_64 
--> Processing Dependency: libonig.so.2()(64bit) for package: jq-1.5-1.2.amzn1.x86_64 
--> Processing Dependency: libjq.so.1()(64bit) for package: jq-1.5-1.2.amzn1.x86_64 
--> Running transaction check 
---> Package jq-libs.x86_64 0:1.5-1.2.amzn1 will be installed 
---> Package oniguruma.x86_64 0:5.9.1-3.1.2.amzn1 will be installed 
--> Finished Dependency Resolution 
 
Dependencies Resolved 
 
========================================================================================================================================= 
 Package                        Arch                        Version                                 Repository                      Size 
========================================================================================================================================= 
Installing: 
 jq                             x86_64                      1.5-1.2.amzn1                           amzn-main                       44 k 
Installing for dependencies: 
 jq-libs                        x86_64                      1.5-1.2.amzn1                           amzn-main                      121 k 
 oniguruma                      x86_64                      5.9.1-3.1.2.amzn1                       amzn-main                      149 k 
 
Transaction Summary 
========================================================================================================================================= 
Install  1 Package (+2 Dependent packages) 
 
Total download size: 314 k 
Installed size: 885 k 
Downloading packages: 
(1/3): jq-1.5-1.2.amzn1.x86_64.rpm                                                                                |  44 kB  00:00:00      
(2/3): jq-libs-1.5-1.2.amzn1.x86_64.rpm                                                                           | 121 kB  00:00:00      
(3/3): oniguruma-5.9.1-3.1.2.amzn1.x86_64.rpm                                                                     | 149 kB  00:00:00      
----------------------------------------------------------------------------------------------------------------------------------------- 
Total                                                                                                    615 kB/s | 314 kB  00:00:00      
Running transaction check 
Running transaction test 
Transaction test succeeded 
Running transaction 
  Installing : oniguruma-5.9.1-3.1.2.amzn1.x86_64                                                                                    1/3  
  Installing : jq-libs-1.5-1.2.amzn1.x86_64                                                                                          2/3  
  Installing : jq-1.5-1.2.amzn1.x86_64                                                                                               3/3  
  Verifying  : oniguruma-5.9.1-3.1.2.amzn1.x86_64                                                                                    1/3  
  Verifying  : jq-1.5-1.2.amzn1.x86_64                                                                                               2/3  
  Verifying  : jq-libs-1.5-1.2.amzn1.x86_64                                                                                          3/3  
 
Installed: 
  jq.x86_64 0:1.5-1.2.amzn1                                                                                                               
 
Dependency Installed: 
  jq-libs.x86_64 0:1.5-1.2.amzn1                                   oniguruma.x86_64 0:5.9.1-3.1.2.amzn1                                   
 
Complete! 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current 
                                 Dload  Upload   Total   Spent    Left  Speed 
100    19  100    19    0     0  24020      0 --:--:-- --:--:-- --:--:-- 19000 
{ 
    "VolumeModification": { 
        "TargetSize": 50,  
        "TargetVolumeType": "gp2",  
        "ModificationState": "modifying",  
        "VolumeId": "vol-xxxxxxxxxxxxxxxxx",  
        "TargetIops": 150,  
        "StartTime": "2019-01-28T02:49:07.000Z",  
        "Progress": 0,  
        "OriginalVolumeType": "gp2",  
        "OriginalIops": 100,  
        "OriginalSize": 8 
    } 
} 
CHANGED: disk=/dev/xvda partition=1: start=4096 old: size=16773086,end=16777182 new: size=104853470,end=104857566 
resize2fs 1.43.5 (04-Aug-2017) 
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required 
old_desc_blocks = 1, new_desc_blocks = 4 
The filesystem on /dev/xvda1 is now 13106683 (4k) blocks long. 


確認する

早速増えたか確認してみます。Cloud9のターミナル上で以下のコマンドを。

Filesystem      Size  Used Avail Use% Mounted on 
devtmpfs         16G   64K   16G   1% /dev 
tmpfs            16G     0   16G   0% /dev/shm 
/dev/xvda1       50G  5.8G   44G  12% / 
増えてますね。Filesystemが/dev/xvda1//にマウントされているやつが今回増やしたものです。簡単にオンラインで増やせるので、これまで作業してきた内容が消えることもないです。


最後に

Cloud9の環境は普通にEC2インスタンス上にセットアップされているので、今回の作業はEBSボリュームのサイズ変更ということになります。

EBSボリュームのサイズ変更そのものは当然ながらCloud9に限った話ではありません。したがってEBSボリュームのサイズ変更にともなう制約事項もあります。そのあたりは以下のリンク先を参考にしてください。

EBS ボリューム変更時の制限

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)