I am trying to launch a instance with CloudFormation Template. Instance was started but the UserData section was not executed completely because cfn-init/aws-cfn-bootstrap
package was not installed in Redhat 7 AMI. I tried installing aws-cfn-bootstrap
package manually but could not install due to the conflicts with python version.
Here is the UserData section of CloudFormation Template
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"\n",
[
"#!/bin/bash",
"set -x",
"",
"INSTANCE_ID=`/opt/aws/bin/ec2-metadata --instance-id | cut -f2 -d' '`",
"REGION=`/opt/aws/bin/ec2-metadata --availability-zone| cut -f2 -d' ' | sed '$s/.$//'`",
{
"Fn::Join": [
"",
[
"AID='",
{
"Fn::GetAtt": [
"eip",
"AllocationId"
]
},
"'"
]
]
},
"aws ec2 associate-address --region $REGION --instance-id $INSTANCE_ID --allocation-id $AID"
]
]
}
}
cloud-init.log
Nov 12 03:55:27 localhost cloud-init: Cloud-init v. 0.7.6 running 'modules:config' at Thu, 12 Nov 2015 08:55:27 +0000. Up 19.01 seconds.
Nov 12 03:55:28 localhost cloud-init: Cloud-init v. 0.7.6 running 'modules:final' at Thu, 12 Nov 2015 08:55:27 +0000. Up 19.67 seconds.
Nov 12 03:55:28 localhost cloud-init: ++ /opt/aws/bin/ec2-metadata --instance-id
Nov 12 03:55:28 localhost cloud-init: /var/lib/cloud/instance/scripts/part-001: line 4: /opt/aws/bin/ec2-metadata: No such file or directory
Nov 12 03:55:28 localhost cloud-init: ++ cut -f2 '-d '
Nov 12 03:55:28 localhost cloud-init: + INSTANCE_ID=
Nov 12 03:55:28 localhost cloud-init: ++ cut -f2 '-d '
Nov 12 03:55:28 localhost cloud-init: ++ sed '$s/.$//'
Nov 12 03:55:28 localhost cloud-init: ++ /opt/aws/bin/ec2-metadata --availability-zone
Nov 12 03:55:28 localhost cloud-init: /var/lib/cloud/instance/scripts/part-001: line 5: /opt/aws/bin/ec2-metadata: No such file or directory
Nov 12 03:55:28 localhost cloud-init: + REGION=
Nov 12 03:55:28 localhost cloud-init: + AID=eipalloc-XXXXXX
Nov 12 03:55:28 localhost cloud-init: + aws ec2 associate-address --region --instance-id --allocation-id eipalloc-XXXXXX
Nov 12 03:55:28 localhost cloud-init: /var/lib/cloud/instance/scripts/part-001: line 7: aws: command not found
Nov 12 03:55:28 localhost cloud-init: 2015-11-12 03:55:28,078 - util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [127]
Nov 12 03:55:28 localhost cloud-init: 2015-11-12 03:55:28,089 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Nov 12 03:55:28 localhost cloud-init: 2015-11-12 03:55:28,089 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/pyt
hon2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Here's what worked for me, i'm not taking full credit for this as I found it on one of the aws forums but now i can't find the source link...anyway i had to modify it a bit to work for me on redhat 6 so hopefully it helps someone else as well.
This is the Userdata section in the template to install the cfn-init scripts:
For RHEL-7.x, you have to add the pypa-repo, below is something worked for me.
You can install it in this way with using only pip (no need to use easy_install):
Source: https://gist.github.com/dasgoll/d533da8a7dc9f05579e2c08ff67788ef