title: Unable to install AWS CLI using CloudFormation UserData in RHEL
body: <p>I am trying to install <code>AWS CLI</code> in a <code>RHEL AMI</code> using <code>CloudFormation</code> <code>UserData</code>, this is what I tried:</p>
  
  <pre><code>"PublicInstance": {
          "Type": "AWS::EC2::Instance",
          "Properties": {
              "ImageId": "ami-b55a51cc",
              "InstanceType": {
                  "Ref": "PublicInstanceType"
              },
              "NetworkInterfaces": [{
                  "AssociatePublicIpAddress": "false",
                  "DeviceIndex": 0,
                  "GroupSet": [{
                  "Ref": "PublicSecurityGroup"
                  }
                  ],
                  "SubnetId": {
                      "Ref": "PublicSubnet"
                  }
              }],
              "InstanceInitiatedShutdownBehavior": "stop",
              "Monitoring": "false",
              "Tenancy": "default",
              "BlockDeviceMappings": [{
                  "DeviceName": "/dev/xvda",
                  "Ebs": {
                  "VolumeType": "io1",
                  "Iops": "200",
                  "DeleteOnTermination": "false",
                  "VolumeSize": "20"
                  }
              }],
              "KeyName": "Testing",
              "Tags": [{
                      "Key": "Name",
                      "Value": "Public Instance"
              }],
              "UserData": { "Fn::Base64" : { "Fn::Join" : ["", [
                  "#!/bin/bash -xe\n",
                  "echo 'Downloading PIP'\n",
                  "curl -O https://bootstrap.pypa.io/get-pip.py\n",
                  "echo 'Executing PIP using Python'\n",
                  "python get-pip.py --user\n",
                  "echo 'Setting PIP Classpath'\n",
                  "echo 'export PATH=~/.local/bin:$PATH' &gt;&gt; ~/.bash_profile\n",
                  "echo 'Reloading bash_profile'\n",
                  "source ~/.bash_profile\n",
                  "echo 'Installing AWS CLI'\n",
                  "pip install awscli --upgrade --user\n"
              ]]}}
          }
      }
  </code></pre>
  
  <p>I can see <code>.bash_profile</code> file is getting updated properly with <code>export PATH</code> at the end, but the installation of <code>pip</code> OR <code>awscli</code> is not happening (<code>pip</code> / <code>aws</code> command says command not found). I checked <code>/var/log/cloud-init.log</code> and it does not show up any error as such:</p>
  
  <pre><code>Jun 29 01:53:09 ip-10-0-1-252 cloud-init: + echo 'Downloading PIP'
  Jun 29 01:53:09 ip-10-0-1-252 cloud-init: Downloading PIP
  Jun 29 01:53:09 ip-10-0-1-252 cloud-init: + curl -O https://bootstrap.pypa.io/get-pip.py
  Jun 29 01:53:09 ip-10-0-1-252 cloud-init: % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  Jun 29 01:53:09 ip-10-0-1-252 cloud-init: Dload  Upload   Total   Spent    Left  Speed
  Jun 29 01:53:34 ip-10-0-1-252 cloud-init: 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0#015  0     0    0     0    0     0
    0      0 --:--:--  0:00:01 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0#015  0     0    0     0    0
    0      0      0 --:--:--  0:00:03 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0#015  0     0    0     0
     0     0      0      0 --:--:--  0:00:05 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:06 --:--:--     0#015  0     0    0
       0    0     0      0      0 --:--:--  0:00:07 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:08 --:--:--     0#015  0
   0    0     0    0     0      0      0 --:--:--  0:00:09 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:10 --:--:--     0#015
    0     0    0     0    0     0      0      0 --:--:--  0:00:11 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:12 --:--:--
    0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:13 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:14 --:-
  -:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:15 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:
  16 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:17 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--
    0:00:18 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:19 --:--:--     0#015  0     0    0     0    0     0      0      0 -
  -:--:--  0:00:20 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:21 --:--:--     0#015  0     0    0     0    0     0      0
      0 --:--:--  0:00:22 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:23 --:--:--     0#015  0     0    0     0    0     0
      0      0 --:--:--  0:00:24 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:25 --:--:--
  Jun 29 01:53:40 ip-10-0-1-252 cloud-init: 0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:26 --:--:--     0#015  0     0    0     0    0
    0      0      0 --:--:--  0:00:27 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:28 --:--:--     0#015  0     0    0     0
     0     0      0      0 --:--:--  0:00:29 --:--:--     0#015  0     0    0     0    0     0      0      0 --:--:--  0:00:30 --:--:--     0#015  0     0    0
       0    0     0      0      0 --:--:--  0:00:31 --:--:--     0#015100 1558k  100 1558k    0     0  50760      0  0:00:31  0:00:31 --:--:--  363k
  Jun 29 01:53:40 ip-10-0-1-252 cloud-init: + echo 'Executing PIP using Python'
  Jun 29 01:53:40 ip-10-0-1-252 cloud-init: Executing PIP using Python
  Jun 29 01:53:40 ip-10-0-1-252 cloud-init: + python get-pip.py --user
  Jun 29 01:53:42 ip-10-0-1-252 cloud-init: Collecting pip
  Jun 29 01:53:42 ip-10-0-1-252 cloud-init: Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
  Jun 29 01:53:42 ip-10-0-1-252 cloud-init: Collecting setuptools
  Jun 29 01:53:43 ip-10-0-1-252 cloud-init: Downloading setuptools-36.0.1-py2.py3-none-any.whl (476kB)
  Jun 29 01:53:43 ip-10-0-1-252 cloud-init: Collecting wheel
  Jun 29 01:53:43 ip-10-0-1-252 cloud-init: Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
  Jun 29 01:53:43 ip-10-0-1-252 cloud-init: Installing collected packages: pip, setuptools, wheel
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: Successfully installed pip-9.0.1 setuptools-36.0.1 wheel-0.29.0
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: + echo 'Setting PIP Classpath'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: Setting PIP Classpath
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: + echo 'export PATH=~/.local/bin:$PATH'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: + echo 'Reloading bash_profile'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: Reloading bash_profile
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: + source /root/.bash_profile
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++ '[' -f /root/.bashrc ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++ . /root/.bashrc
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++ alias 'rm=rm -i'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++ alias 'cp=cp -i'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++ alias 'mv=mv -i'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++ '[' -f /etc/bashrc ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++ . /etc/bashrc
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ shopt -q login_shell
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' 0 -gt 199 ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ umask 022
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ SHELL=/bin/bash
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ for i in '/etc/profile.d/*.sh'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' -r /etc/profile.d/256term.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ . /etc/profile.d/256term.sh
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ local256=
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' -n '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' -n '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ unset local256
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ for i in '/etc/profile.d/*.sh'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' -r /etc/profile.d/colorgrep.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ . /etc/profile.d/colorgrep.sh
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ /usr/libexec/grepconf.sh -c
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ alias 'grep=grep --color=auto'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ alias 'egrep=egrep --color=auto'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ alias 'fgrep=fgrep --color=auto'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ for i in '/etc/profile.d/*.sh'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' -r /etc/profile.d/colorls.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ . /etc/profile.d/colorls.sh
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' '!' -t 0 ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ return
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ for i in '/etc/profile.d/*.sh'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' -r /etc/profile.d/lang.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ . /etc/profile.d/lang.sh
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ sourced=0
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' -n en_US.UTF-8 ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ saved_lang=en_US.UTF-8
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' -f /.i18n ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ LANG=en_US.UTF-8
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ unset saved_lang
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' 0 = 1 ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ unset sourced
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ unset langfile
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ for i in '/etc/profile.d/*.sh'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' -r /etc/profile.d/less.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ . /etc/profile.d/less.sh
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ '[' -x /usr/bin/lesspipe.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ export 'LESSOPEN=||/usr/bin/lesspipe.sh %s'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ LESSOPEN='||/usr/bin/lesspipe.sh %s'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ for i in '/etc/profile.d/*.sh'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' -r /etc/profile.d/which2.sh ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ '[' '' ']'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ . /etc/profile.d/which2.sh
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: +++++ alias 'which=alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ unset i
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++++ unset -f pathmunge
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++ export PATH
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++ export PATH=/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: ++ PATH=/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: + echo 'Installing AWS CLI'
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: Installing AWS CLI
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: + pip install awscli --upgrade --user
  Jun 29 01:53:44 ip-10-0-1-252 cloud-init: Collecting awscli
  Jun 29 01:53:45 ip-10-0-1-252 cloud-init: Downloading awscli-1.11.113-py2.py3-none-any.whl (1.2MB)
  Jun 29 01:53:45 ip-10-0-1-252 cloud-init: Collecting botocore==1.5.76 (from awscli)
  Jun 29 01:53:46 ip-10-0-1-252 cloud-init: Downloading botocore-1.5.76-py2.py3-none-any.whl (3.5MB)
  Jun 29 01:53:46 ip-10-0-1-252 cloud-init: Collecting rsa&lt;=3.5.0,&gt;=3.1.2 (from awscli)
  Jun 29 01:53:46 ip-10-0-1-252 cloud-init: Downloading rsa-3.4.2-py2.py3-none-any.whl (46kB)
  Jun 29 01:53:46 ip-10-0-1-252 cloud-init: Collecting s3transfer&lt;0.2.0,&gt;=0.1.9 (from awscli)
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Downloading s3transfer-0.1.10-py2.py3-none-any.whl (54kB)
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Collecting docutils&gt;=0.10 (from awscli)
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Downloading docutils-0.13.1-py2-none-any.whl (537kB)
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Collecting colorama&lt;=0.3.7,&gt;=0.2.5 (from awscli)
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Downloading colorama-0.3.7-py2.py3-none-any.whl
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Collecting PyYAML&lt;=3.12,&gt;=3.10 (from awscli)
  Jun 29 01:53:47 ip-10-0-1-252 cloud-init: Downloading PyYAML-3.12.tar.gz (253kB)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Collecting python-dateutil&lt;3.0.0,&gt;=2.1 (from botocore==1.5.76-&gt;awscli)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Collecting jmespath&lt;1.0.0,&gt;=0.7.1 (from botocore==1.5.76-&gt;awscli)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Downloading jmespath-0.9.3-py2.py3-none-any.whl
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Collecting pyasn1&gt;=0.1.3 (from rsa&lt;=3.5.0,&gt;=3.1.2-&gt;awscli)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Downloading pyasn1-0.2.3-py2.py3-none-any.whl (53kB)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Collecting futures&lt;4.0.0,&gt;=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer&lt;0.2.0,&gt;=0.1.9
  -&gt;awscli)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Downloading futures-3.1.1-py2-none-any.whl
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Collecting six&gt;=1.5 (from python-dateutil&lt;3.0.0,&gt;=2.1-&gt;botocore==1.5.76-&gt;awscli)
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Downloading six-1.10.0-py2.py3-none-any.whl
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Building wheels for collected packages: PyYAML
  Jun 29 01:53:48 ip-10-0-1-252 cloud-init: Running setup.py bdist_wheel for PyYAML: started
  Jun 29 01:53:49 ip-10-0-1-252 cloud-init: Running setup.py bdist_wheel for PyYAML: finished with status 'done'
  Jun 29 01:53:49 ip-10-0-1-252 cloud-init: Stored in directory: /root/.cache/pip/wheels/2c/f7/79/13f3a12cd723892437c0cfbde1230ab4d82947ff7b3839a4fc
  Jun 29 01:53:49 ip-10-0-1-252 cloud-init: Successfully built PyYAML
  Jun 29 01:53:49 ip-10-0-1-252 cloud-init: Installing collected packages: six, python-dateutil, jmespath, docutils, botocore, pyasn1, rsa, futures, s3transfer
  , colorama, PyYAML, awscli
  Jun 29 01:53:50 ip-10-0-1-252 cloud-init: Successfully installed PyYAML-3.12 awscli-1.11.113 botocore-1.5.76 colorama-0.3.7 docutils-0.13.1 futures-3.1.1 jme
  spath-0.9.3 pyasn1-0.2.3 python-dateutil-2.6.0 rsa-3.4.2 s3transfer-0.1.10 six-1.10.0
  Jun 29 01:53:51 ip-10-0-1-252 cloud-init: 2017-06-29 01:53:51,092 - templater.py[WARNING]: Cheetah not available as the default renderer for unknown template
  , reverting to the basic renderer.
  Jun 29 01:53:51 ip-10-0-1-252 cloud-init: Cloud-init v. 0.7.6 finished at Thu, 29 Jun 2017 05:53:51 +0000. Datasource DataSourceEc2.
  </code></pre>
  
  <p>Please let me know where lies the issue and how to resolve this issue.</p>