启动期间的 AWS 轮询扩展组
AWS Polling Scaling Group During Boot
我正在尝试轮询 AWS Scaling Group 的当前成员,以便我可以在我的代码中递增一个值。我需要能够根据活动成员的数量分配工作进程。我在 rc.local 下在新的缩放组成员上创建了一个 运行 的脚本:
for ((i=0; i<20; i++)); do
OUT=$(aws autoscaling describe-auto-scaling-instances --query AutoScalingInstances[].InstanceId | wc -l)
echo "Output is $OUT" >> /tmp/ec2log
echo "Waiting for a response...." >> /tmp/ec2log
ping -c 5 127.0.0.1 &> /dev/null # Wait for a bit before retrying
done
我的问题(以及我循环执行命令的原因)是 AWS CLI 似乎没有响应我的初始请求。
如何将缩放组中的当前服务器数量传递给添加到该组的新服务器?
当您 运行 此脚本时网络可能无法启动,这就是为什么 aws cli 没有响应并且您的脚本应该在成功时调用 exit 0
的原因。在 rc.local 中执行脚本是错误的,因为它在每个 运行 级别的末尾执行。
我会调用 aws autoscaling describe-auto-scaling-instances --region us-east-1 --query AutoScalingInstances[].InstanceId --output text | wc -w 在您的代码中获取自动缩放组中的成员数量。
rc.local
#
This script is executed at the end of each multiuser runlevel.
Make sure that the script will "exit 0" on success or any other
value on error.
我正在尝试轮询 AWS Scaling Group 的当前成员,以便我可以在我的代码中递增一个值。我需要能够根据活动成员的数量分配工作进程。我在 rc.local 下在新的缩放组成员上创建了一个 运行 的脚本:
for ((i=0; i<20; i++)); do
OUT=$(aws autoscaling describe-auto-scaling-instances --query AutoScalingInstances[].InstanceId | wc -l)
echo "Output is $OUT" >> /tmp/ec2log
echo "Waiting for a response...." >> /tmp/ec2log
ping -c 5 127.0.0.1 &> /dev/null # Wait for a bit before retrying
done
我的问题(以及我循环执行命令的原因)是 AWS CLI 似乎没有响应我的初始请求。
如何将缩放组中的当前服务器数量传递给添加到该组的新服务器?
当您 运行 此脚本时网络可能无法启动,这就是为什么 aws cli 没有响应并且您的脚本应该在成功时调用 exit 0
的原因。在 rc.local 中执行脚本是错误的,因为它在每个 运行 级别的末尾执行。
我会调用 aws autoscaling describe-auto-scaling-instances --region us-east-1 --query AutoScalingInstances[].InstanceId --output text | wc -w 在您的代码中获取自动缩放组中的成员数量。
rc.local
#
This script is executed at the end of each multiuser runlevel.
Make sure that the script will "exit 0" on success or any other
value on error.