gpt4 book ai didi

amazon-web-services - 如何从命令行复制 ec2 "launch more like this"?

转载 作者:行者123 更新时间:2023-12-03 00:26:20 26 4
gpt4 key购买 nike

aws ec2 界面有一个名为“launch more like this”的按钮,可启动第二个实例(如所选实例)。据我所知,aws 命令行界面中没有类似的功能。

最佳答案

这是一种将实例构建为另一个实例的副本的有效方法(尽管有些拙劣):

function cloneinstance {
awsinstanceid=$1
region=$2
export AWS_DEFAULT_REGION=$region
ami=$(aws ec2 describe-instances --instance-ids $awsinstanceid | grep INSTANCES | awk '{print $7}')
privatekey=$(aws ec2 describe-instances --instance-ids $awsinstanceid | grep INSTANCES | awk '{print $10}')
securitygroup=$(aws ec2 describe-instances --instance-ids $awsinstanceid | grep SECURITYGROUPS | awk '{print $2}')
instancetype=$(aws ec2 describe-instances --instance-ids $awsinstanceid | grep INSTANCES | awk '{print $9}')
subnet=$(aws ec2 describe-instances --instance-ids $awsinstanceid | grep NETWORKINTERFACES | awk '{print $9}')

awsinstancedata=$(aws ec2 run-instances --image-id $ami --key-name $privatekey --security-group-ids $securitygroup --instance-type $instancetype --subnet-id $subnet)
awsinstanceid=$(echo $awsinstancedata | awk '{print $9}')

# AWS CLI sucks and doesn't return error codes so have to look for a valid id
if [[ "$awsinstanceid" == i-* ]]; then echo -e "\t\tSuccessfully created. Instance ID: $awsinstanceid"; else echo -e "\t\tSomething went wrong. Check your configuration."; exit 1; fi
echo -e "\t\tWaiting for it to come up..."
aws ec2 wait instance-running --instance-ids $awsinstanceid
echo -e "\t\tServer is up and ready"
}

cloneinstance i-12345678 us-west-1

关于amazon-web-services - 如何从命令行复制 ec2 "launch more like this"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33528804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com