在这一节,我们将在AWS帐号下创建Cloud9 IDE,作为后续实验的代码编辑工具
在AWS控制台上,切换到us-east-1
地区,搜索Cloud9服务:
在Cloud9控制台,点击Create environment
:
输入环境的名称(如serverless-lab
)和描述:
点击进入下一步。在Configure settings
步骤, 机型型号选择m5.large
,然后点击Next step:
进入下一步,并点击Create Environment
创建Cloud9, 整个创建过程会持续大概2-3分钟。
cloud 9已经为我们预安装好常见的开发环境,执行以下命令检查对应的版本:
docker version
aws --version
node --version
sam --version
python -V # i.e. 3.7.10
在Cloud 9编辑代码完成后,编辑器默认不会自动保存文件,建议开启此配置(On Focus Change
):
默认Cloud 9的EBS卷是10GB,后面的实验要下载很多docker镜像,很容易占满。我们将使用脚本将其扩容到30GB。
在terminal中创建ebs-resize.sh
:
内容如下:
#!/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
执行完成后,查看磁盘空间进行确认:
默认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版本:
参考: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html