aws / amazon-ecs-cli

The Amazon ECS CLI enables users to run their applications on ECS/Fargate using the Docker Compose file format, quickly provision resources, push/pull images in ECR, and monitor running applications on ECS/Fargate.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html
Other
1.78k stars 303 forks source link

`ecs-cli up` doesn't attach EC2 instances when using `--extra-user-data` #1126

Closed pbendersky closed 3 years ago

pbendersky commented 3 years ago

Summary

When I add --extra-user-data to ecs-cli up, the cluster is created, but no EC2 instances are attached. The same command with no --extra-user-data works.

Description

I'm running this command (I've redacted my information):

ecs-cli up --keypair keyPair --instance-role ecsInstanceRole --instance-type t3a.medium --cluster-config staging --ecs-profile default --vpc vpc-xxxx --subnets subnet-xxxx --security-group sg-xxxx --launch-type EC2 --region us-east-1 --force --debug

Running this creates the cluster with 1 EC2 instance attached.

I now want to do the same, but attach a script to be run on newly created EC2 instances, so I do:

ecs-cli up --keypair keyPair --instance-role ecsInstanceRole --instance-type t3a.medium --cluster-config staging --ecs-profile default --vpc vpc-xxxx --subnets subnet-xxxx --security-group sg-xxxx --launch-type EC2 --extra-user-data installRexRay.sh --region us-east-1 --force --debug

Doing that causes the cluster to be properly created, but with no EC2 instances attached. No errors are reported.

ecs-cli version 1.21.0 (*UNKNOWN)

I don't have go installed.

macOS

Config files

Contents of installRexRay.sh:

#!/bin/sh

# From https://aws.amazon.com/blogs/compute/amazon-ecs-and-docker-volume-drivers-amazon-ebs/

#open file descriptor for stderr
exec 2>>/var/log/ecs/ecs-agent-install.log
set -x
#verify that the agent is running
until curl -s http://localhost:51678/v1/metadata
do
    sleep 1
done
#install the Docker volume plugin
docker plugin install rexray/ebs REXRAY_PREEMPT=true EBS_REGION=us-east-1 --grant-all-permissions
#restart the ECS agent
stop ecs
start ecs

Expected Behavior

ECS cluster created with 1 EC2 instance attached.

Observed Behavior

ECS cluster created with no EC2 instance attached.

INFO[0002] Using recommended Amazon Linux 2 AMI with ECS Agent 1.50.2 and Docker version 19.03.13-ce
INFO[0003] Created cluster                               cluster=cluster-staging region=us-east-1
DEBU[0005] Cloudformation create stack call succeeded    stackId=0xc0005282c8
INFO[0005] Waiting for your cluster resources to be created...
DEBU[0005] parsing event                                 eventStatus=CREATE_IN_PROGRESS resource="arn:aws:cloudformation:us-east-1:081740113988:stack/amazon-ecs-cli-setup-cluster-staging/2ba812f0-7864-11eb-9b02-12e346dd5d0c"
INFO[0005] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
DEBU[0036] parsing event                                 eventStatus=CREATE_IN_PROGRESS resource=amazon-ecs-cli-setup-cluster-staging-EcsInstanceProfile-1VEH68SFESRSB
DEBU[0036] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
DEBU[0067] parsing event                                 eventStatus=CREATE_IN_PROGRESS resource=amazon-ecs-cli-setup-cluster-staging-EcsInstanceProfile-1VEH68SFESRSB
INFO[0067] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
DEBU[0098] parsing event                                 eventStatus=CREATE_IN_PROGRESS resource=amazon-ecs-cli-setup-cluster-staging-EcsInstanceProfile-1VEH68SFESRSB
DEBU[0098] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
DEBU[0129] parsing event                                 eventStatus=CREATE_IN_PROGRESS resource=amazon-ecs-cli-setup-cluster-staging-EcsInstanceProfile-1VEH68SFESRSB
INFO[0129] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
DEBU[0160] parsing event                                 eventStatus=CREATE_COMPLETE resource="arn:aws:cloudformation:us-east-1:081740113988:stack/amazon-ecs-cli-setup-cluster-staging/2ba812f0-7864-11eb-9b02-12e346dd5d0c"
Cluster creation succeeded.