Clood9の開発環境でAmazon EBS ボリュームを増量してみました

回線速度は遅くないにもかかわらず、Cloud9の開発環境で所々遅延を感じていたところ(Sassコマンドを実行後のCSSファイル変換や、固定ページの編集等)、AWSから「改善の通知(ボリューム増量 or 環境移行 or 暗号化)」の重要そうな案内が来ました。

案内は英語で来ましたが、後に日本語ページのバージョンも発見しました。
このページ内容を引用し私が実際に行ったことを記載しておりますが、環境の改善及び変更は、慎重に自己責任においてお願いいたします。
より詳細を知りたい方は上記のAWSのリンクからページ遷移していただければと思います。

手順

  • ボリュームサイズ変更用のファイルを作成
  • コマンドの実行
  • (私は、万が一のため、事前にバックアップを作成しました)
  • 増量されたボリュームを確認

SHファイルの作成

ボリュームサイズを変更したいワークスペースにて、AWSから案内が来た下記の内容コピペし、拡張子を.shとしたファイル(例:「resize.sh」)を作成し保存します。
下記はAWS Cloud9ユーザーガイドに記載されていたものですが、環境によってや今後変更の可能性もあるかもしれませんので、公式ページからのコピペをお奨めします。

#!/bin/bash

# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}

# Get the ID of the environment 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 \
  --query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \
  --output text)

# 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" \
    --query "length(VolumesModifications)"\
    --output text)" != "1" ]; do
sleep 1
done

#Check if we're on an NVMe filesystem
if [ $(readlink -f /dev/xvda) = "/dev/xvda" ]
then
  # 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.
  # Check if we are on AL2
  STR=$(cat /etc/os-release)
  SUB="VERSION_ID=\"2\""
  if [[ "$STR" == *"$SUB"* ]]
  then
    sudo xfs_growfs -d /
  else
    sudo resize2fs /dev/xvda1
  fi

else
  # Rewrite the partition table so that the partition takes up all the space that it can.
  sudo growpart /dev/nvme0n1 1

  # Expand the size of the file system.
  # Check if we're on AL2
  STR=$(cat /etc/os-release)
  SUB="VERSION_ID=\"2\""
  if [[ "$STR" == *"$SUB"* ]]
  then
    sudo xfs_growfs -d /
  else
    sudo resize2fs /dev/nvme0n1p1
  fi
fi

このスクリプトは Amazon Linux 2、Amazon Linux、または Ubuntu サーバーを実行する EC2 インスタンスに接続されている Amazon EBS ボリュームに対して機能します。

このスクリプトは、Nitro ベースのインスタンスで NVMe ブロックデバイスとして公開される Amazon EBS ボリュームのサイズも変更します。Nitro システムに基づくインスタンスのリストについては、「」を参照してください。Nitroベースのインスタンス()Linux インスタンス用 Amazon EC2 ユーザーガイド

AWS Cloud9 ユーザーガイド

コマンド実行

IDEターミナルセッションから、resize.shファイルを含むディレクトリに切り替え、次のコマンドを実行します。
最後の数字は変更したいGiBサイズに置き換えます。

bash resize.sh 20

ターミナル上で2~3分経過後、以下の結果が表示されました。

ubuntu:~/environment $ bash resize.sh 20
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    19  100    19    0     0    243      0 --:--:-- --:--:-- --:--:--   243
{
    "VolumeModification": {
        "VolumeId": "xxxxxxxxxxxxxxxxxxxx",  
        "ModificationState": "modifying",
        "TargetSize": 20,
        "TargetIops": 100,
        "TargetVolumeType": "gp2",
        "TargetMultiAttachEnabled": false,
        "OriginalSize": 12,
        "OriginalIops": 100,
        "OriginalVolumeType": "gp2",
        "OriginalMultiAttachEnabled": false,
        "Progress": 0,
        "StartTime": "2021-07-03T02:32:14.000Z"
    }
}
CHANGED: partition=1 start=2048 old: size=25163743 end=25165791 new: size=41940959,end=41943007
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/xvda1 is now 5242619 (4k) blocks long.

結果

ダッシュボード > サービス > EC2  > 左側メニューのボリューム で結果を確認したところ、無事にボリュームが増えていることが確認できました。

volume

快適になったかというと、劇的にとまではいかないもののよくなったような気はします。
他に思い当たることといえば、AWSデフォルトのWordPress及びPHPのバージョンを上げたことでしょうか。

これとは別に、WordPress開発終了後(インスタンス再起動後)に開発用管理画面にアクセスできなくなった時の対応をこちらに記載しておりますので、ご参考になれば幸いです。

タイトルとURLをコピーしました