简体   繁体   中英

How to add an EC2 instance created with autoscaling group and ECS IAM to OpsWorks stack?

I have an AWS ECS cluster and to ease user's access I'm using OpsWorks to get its ssh feature. In order to keep the stack always up even when an instance is for any reason terminated, I'm relying on an EC2 Auto Scaling Group that makes use of an specific Launch Configuration and there I set the following on the User Data field:

#!/bin/bash
# This works just fine!
echo ECS_CLUSTER=my-cluster-name >> /etc/ecs/ecs.config
# Given AWS CLI is not installed by default
yum install -y awscli
# This is copied and pasted from the OpsWorks' Register Instance Wizard
aws opsworks register --infrastructure-class ec2 --region us-east-1 --stack-id aaa-bbb-ccc-ddd --local

For debugging I've set -x in place and given all commands before registration work here is the relevant log about the specific command output:

+ aws opsworks register --use-instance-profile --infrastructure-class ec2 --region us-east-1 --stack-id aaa-bbb-ccc-ddd --override-hostname abcdefgh --local
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 7800k  100 7800k    0     0  12.3M      0 --:--:-- --:--:-- --:--:-- 12.3M
opsworks-init: Initializing AWS OpsWorks environment
opsworks-init: Checking if OS is supported
opsworks-init: Running on supported OS
opsworks-init: Setup motd
opsworks-init: Executing: ln -sf --backup /etc/motd.opsworks-static /etc/motd
opsworks-init: Using assets bucket from environment: 'opsworks-instance-assets-us-east-1.s3.amazonaws.com'.
opsworks-init: Installing Ruby for the agent
opsworks-init: Executing: /tmp/opsworks-agent-installer.ggXxYyMmBBH/opsworks-agent-installer/opsworks-agent/bin/installer_wrapper.sh -r -R opsworks-instance-assets-us-east-1.s3.amazonaws.com

The impression I have here is that this last command is failing silently because I'd expect the registration to be a bit more verbose right after that.

After making sure all IAM roles and Security Groups are revised and all look clear and with no explicit errors showing on the boot logs, the instance will not register at all. I've already tried following this Auto Scaling AWS OpsWorks instances guide but even with this code below extracted from there (and after trying many variations) it won't register:

#!/bin/bash
sed -i'' -e 's/.*requiretty.*//' /etc/sudoers
pip install --upgrade awscli
/usr/bin/aws opsworks register --use-instance-profile --infrastructure-class ec2 --region us-east-1 --stack-id aaa-bbb-ccc-ddd --override-hostname $(tr -cd 'a-z' < /dev/urandom |head -c8) --local

Any clues on what I may be missing in order to register new instances to an OpsWorks stack?

Thanks a lot!

I had a similar problem and updated the version of opsworks agent:

Stack-> Stack Settings-> Edit-> OpsWorks Agent version-> Use latest version

after this little change, everything worked perfectly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM