안녕하세요 오늘은 BESPIN GLOBAL SRE실 송효종님이 작성해주신 ‘AWS Cloud9 사용 가이드’에 대해 소개해드리도록 하겠습니다.
목차
- 목표
- 생성 리소스
- 필요 항목
- 매뉴얼
- Cloud9 생성(Private 네트워크 망)
- Cloud9 디스크 리사이즈
- Cloud9 파일 업로드 & 파일 다운로드
- 서비스 기동시 Cloud9 내부 브라우저로 확인 방법
1. 목표
개발 환경에서 테스트를 위한 Cloud9(EC2) 을 생성하여 어플리케이션 작업을 진행합니다.
2. 생성 리소스
- AWS Cloud9
3. 필요 항목
- Private 네트워크에 Cloud9 생성 및 SSM 접근 방법
- 디스크 사이즈 부족할 시 리사이즈 방법
- 파일 업로드 & 다운로드 방법
- 애플리케이션 서비스 기동시 Cloud9 내부 브라우저로 확인하는 방법
4. 매뉴얼
- Cloud9 생성(Private 네트워크 망)
- Cloud9 생성 시 Security Group과 SSM 관련 IAM Role이 자동으로 Attach 됩니다.

- Name environment
- Name: {계정 코드}-{환경 코드}-{서비스 코드}-{추가 식별자 코드}-c9

- Configuration Settings
- Environment type: Create a new no-ingress EC2 instance for environment (access via Systems Manager) → SSM으로 접근하기 위함
- Instance type: 개발 환경 테스트에 맞게 type 설정
- Platform: Amazon Linux 2
- Cost-saving setting: Default는 30분이며, 설정한 시간 동안 AWS Cloud9 환경에서 작업이 없을 경우 자동으로 Cloud9 중지
- Network Settings
- Network (VPC): VPC 선택
- Subnet: Private 망 Subnet 선택





2. Cloud9 디스크 리사이즈
- aws configure 값 필수 기입
- resize.sh 파일 실행시 인자 값 없을 경우 기본 20GiB로 증설
- 루트 디바이스 볼륨 크기 증설 후 즉시 추가 증설은 불가능 (즉시 추가 증설이 필요할 경우 6시간 후 가능)
resize.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}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/\(.*\)[a-z]/\1/')
# 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
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
- Linux Command
# root 전환
sudo su -
cd /home/ec2-user/environment
# 폴더 생성
mkdir disk_size
cd disk_size
# resize.sh 내용 기입
cat > resize.sh
# AWS 계정 token 값 설정
export AWS_ACCESS_KEY_ID= Access Key ID 값 기입
export AWS_SECRET_ACCESS_KEY= Secret Access Key 값 기입
export AWS_SESSION_TOKEN= AWS Session Token 값 기입
# AWS configure 값 설정
aws configure
AWS Access Key ID []: Access Key ID 값 기입
AWS Secret Access Key []: Secret Access Key 값 기입
Default region name []: region 값 기입
Default output format []: json
# 루트 디바이스 크기 확인
df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 970M 0 970M 0% /dev
tmpfs tmpfs 978M 0 978M 0% /dev/shm
tmpfs tmpfs 978M 468K 977M 1% /run
tmpfs tmpfs 978M 0 978M 0% /sys/fs/cgroup
/dev/nvme0n1p1 xfs 10G 5.7G 4.4G 57% /
tmpfs tmpfs 196M 0 196M 0% /run/user/1000
# resize.sh 파일 실행 권한 추가
chmod 755 resize.sh
# resize.sh 파일 실행
./resize.sh 50
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 19 100 19 0 0 22974 0 --:--:-- --:--:-- --:--:-- 19000
{
"VolumeModification": {
"TargetSize": 50,
"OriginalMultiAttachEnabled": false,
"TargetVolumeType": "gp2",
"ModificationState": "modifying",
"TargetMultiAttachEnabled": false,
"VolumeId": "vol-00989cb0be7a28826",
"TargetIops": 150,
"StartTime": "2022-08-04T03:59:57.000Z",
"Progress": 0,
"OriginalVolumeType": "gp2",
"OriginalIops": 100,
"OriginalSize": 10
}
}
CHANGED: partition=1 start=4096 old: size=20967391 end=20971487 new: size=104853471 end=104857567
meta-data=/dev/nvme0n1p1 isize=512 agcount=6, agsize=524159 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1 spinodes=0
data = bsize=4096 blocks=2620923, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2620923 to 13106683
# 루트 디바이스 크기 확인
df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 970M 0 970M 0% /dev
tmpfs tmpfs 978M 0 978M 0% /dev/shm
tmpfs tmpfs 978M 516K 977M 1% /run
tmpfs tmpfs 978M 0 978M 0% /sys/fs/cgroup
/dev/nvme0n1p1 xfs 50G 5.7G 45G 12% /
tmpfs tmpfs 196M 0 196M 0% /run/user/1000
tmpfs tmpfs 196M 0 196M 0% /run/user/0
3. Cloud9 파일 업로드 & 파일 다운로드
- 파일 업로드: local → Cloud9 환경에 마우스 드래그로 파일 업로드 가능


- 파일 다운로드: Cloud9 → local 환경 파일 다운로드

4. 서비스 기동시 Cloud9 내부 브라우저로 확인 방법
- 사전 조건
- Cloud9 내 실행할 애플리케이션 (필자는 Tomcat으로 확인)
- Chrome 타사 쿠키 활성화 확인 (설정 → 개인정보 및 보안) → 쿠키 및 기타 사이트 데이터 → 모든 쿠키 허용 & 시크릿 모드에서 타사 쿠키 차단

- Tomcat 기동 & Cloud9 브라우저 확인


여기까지 ‘AWS Cloud9 사용 가이드’에 대해 소개해드렸습니다. 유익한 정보가 되셨길 바랍니다. 감사합니다.
Written by 송 효종 / SRE실
BESPIN GLOBAL