

 AWS Cloud9 는 더 이상 신규 고객이 사용할 수 없습니다. AWS Cloud9 의 기존 고객은 정상적으로 서비스를 계속 이용할 수 있습니다. [자세히 알아보기](https://aws.amazon.com/blogs/devops/how-to-migrate-from-aws-cloud9-to-aws-ide-toolkits-or-aws-cloudshell/)

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 환경에서 사용하는 Amazon EBS 볼륨 크기 조정
<a name="move-environment-resize"></a>

이 단계에서는 Amazon EBS 볼륨의 크기를 조정할 수 있는 방법을 설명합니다.

1. 크기를 조정할 Amazon EBS 볼륨에 대해 Amazon EC2 인스턴스와 연결된 환경을 엽니다.

1. 환경의 AWS Cloud9 IDE에서 다음 내용이 포함된 파일을 생성한 다음 확장명과 함께 파일을 저장합니다`.sh`(예: `resize.sh`).
**Note**  
이 스크립트는 AL2023, Amazon Linux 2, Amazon Linux 또는 Ubuntu 서버를 실행하는 EC2 인스턴스에 연결된 Amazon EBS 볼륨에 적용되며 IMDSv2를 사용하도록 구성됩니다.  
또한 이 스크립트는 Nitro 기반 인스턴스에 NVMe 블록 디바이스로 표시된 Amazon EBS 볼륨의 크기를 조정합니다. Nitro 시스템을 기반으로 한 인스턴스의 목록은 *Amazon EC2 사용 설명서*에서 [Nitro 기반 인스턴스](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances)를 참조하세요.

   ```
   #!/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.
   TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
   INSTANCEID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null)
   REGION=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/placement/region 2> /dev/null)
   
   # 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 \
     --region $REGION)
   
   # 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 [[ -e "/dev/xvda" && $(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're on AL2 or AL2023
     STR=$(cat /etc/os-release)
     SUBAL2="VERSION_ID=\"2\""
     SUBAL2023="VERSION_ID=\"2023\""
     if [[ "$STR" == *"$SUBAL2"* || "$STR" == *"$SUBAL2023"* ]]
     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 or AL2023
     STR=$(cat /etc/os-release)
     SUBAL2="VERSION_ID=\"2\""
     SUBAL2023="VERSION_ID=\"2023\""
     if [[ "$STR" == *"$SUBAL2"* || "$STR" == *"$SUBAL2023"* ]]
     then
       sudo xfs_growfs -d /
     else
       sudo resize2fs /dev/nvme0n1p1
     fi
   fi
   ```

1. IDE의 터미널 세션에서 `resize.sh` 파일을 포함하는 디렉터리로 전환합니다. 그리고 나서 다음 명령 중 하나를 실행하여 Amazon EBS Volume의 크기를 조정하기 위해 `20`을 원하는 크기(단위: GIB)로 바꿉니다.
   + 

     ```
     bash resize.sh 20
     ```
   + 

     ```
     chmod +x resize.sh
     ./resize.sh 20
     ```