Cloud 9创建及配置

在这一节,我们将在AWS帐号下创建Cloud9 IDE,作为后续实验的代码编辑工具

在AWS控制台上,切换到us-east-1地区,搜索Cloud9服务:

image-20210430170852514

在Cloud9控制台,点击Create environment

image-20210430172234510

输入环境的名称(如serverless-lab)和描述:

image-20220306203635502

点击进入下一步。在Configure settings步骤, 机型型号选择m5.large,然后点击Next step:

image-20220103233720169

进入下一步,并点击Create Environment创建Cloud9, 整个创建过程会持续大概2-3分钟。


检查已安装好的软件

cloud 9已经为我们预安装好常见的开发环境,执行以下命令检查对应的版本:

docker version
aws --version
node --version
sam --version
python -V   # i.e.  3.7.10

image-20220306204600032

配置文件自动保存

在Cloud 9编辑代码完成后,编辑器默认不会自动保存文件,建议开启此配置(On Focus Change):

image-20220306210257529

调整Cloud 9 磁盘大小

默认Cloud 9的EBS卷是10GB,后面的实验要下载很多docker镜像,很容易占满。我们将使用脚本将其扩容到30GB。

在terminal中创建ebs-resize.sh

image-20220306222717556

内容如下:

#!/bin/bash

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

# 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


# 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.
sudo xfs_growfs -d /

执行:

chmod +x ebs-resize.sh
./ebs-resize.sh

执行完成后,查看磁盘空间进行确认:

image-20220306223311357

更新AWS CLI版本

默认Cloud 9安装的AWS CLI大版本是1, 例如1.19.xxx

kongpingfan:~/environment $ aws --version
aws-cli/1.19.112 Python/2.7.18 Linux/4.14.262-200.489.amzn2.x86_64 botocore/1.20.112

在后面要使用AWS CLI v2进行实验,使用以下命令对其更新:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

安装完成后,打开新的terminal确认cli版本:

image-20220308221118873

参考: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html