我正在尝试启动一个ECS contianer实例,并通过用户数据将其注册到集群中,并开始运行任务定义。
当任务完成时,实例将被终止。
我正在使用AWS文档指南在容器启动时启动一个任务。在userdata下面(省略了集群和任务def参数)
Content-Type: multipart/mixed; boundary="==BOUNDARY=="
MIME-Version: 1.0
--==BOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
# Specify the cluster that the container instance should register into
cluster=my_cluster
# Write the cluster configuration variable to the ecs.config file
# (add any other configuration variables here also)
echo ECS_CLUSTER=$cluster >> /etc/ecs/ecs.config
# Install the AWS CLI and the jq JSON parser
yum install -y aws-cli jq
--==BOUNDARY==
Content-Type: text/upstart-job; charset="us-ascii"
#upstart-job
description "Amazon EC2 Container Service (start task on instance boot)"
author "Amazon Web Services"
start on started ecs
script
exec 2>>/var/log/ecs/ecs-start-task.log
set -x
until curl -s http://localhost:51678/v1/metadata
do
sleep 1
done
# Grab the container instance ARN and AWS region from instance metadata
instance_arn=$(curl -s http://localhost:51678/v1/metadata | jq -r '. | .ContainerInstanceArn' | awk -F/ '{print $NF}' )
cluster=$(curl -s http://localhost:51678/v1/metadata | jq -r '. | .Cluster' | awk -F/ '{print $NF}' )
region=$(curl -s http://localhost:51678/v1/metadata | jq -r '. | .ContainerInstanceArn' | awk -F: '{print $4}')
# Specify the task definition to run at launch
task_definition=my_task_def
# Run the AWS CLI start-task command to start your task on this container instance
aws ecs start-task --cluster $cluster --task-definition $task_definition --container-instances $instance_arn --started-by $instance_arn --region $region
end script
--==BOUNDARY==--
当创建实例时,它将被启动到默认集群,而不是我在userdata中指定的集群,并且没有启动任务。
我已经解构了上面的脚本,找出它的失败之处,但我没有运气。
任何帮助都将不胜感激。
发布于 2018-05-01 12:36:26
来自AWS文件。
使用用户数据配置Amazon容器实例,例如Amazon容器代理配置中的代理环境变量。当第一次启动该实例时,亚马逊EC2用户数据脚本只执行一次。 默认情况下,容器实例将启动到默认集群中。若要启动到非默认群集,请选择“高级详细信息”列表。然后,将下面的脚本粘贴到用户数据字段中,用集群的名称替换your_cluster_name。
因此,为了能够将这个EC2实例添加到您的ECS集群中,您应该将这个变量更改为集群的名称:
# Specify the cluster that the container instance should register into
cluster=your_cluster_name
将your_cluster_name更改为集群的任何名称。
https://stackoverflow.com/questions/50115174
复制相似问题