代码之家  ›  专栏  ›  技术社区  ›  user182944

无法在RHEL中使用CloudFormation UserData安装AWS CLI

  •  1
  • user182944  · 技术社区  · 9 年前

    AWS CLI RHEL AMI 使用 CloudFormation UserData ,这是我尝试的:

    "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' >> ~/.bash_profile\n",
                    "echo 'Reloading bash_profile'\n",
                    "source ~/.bash_profile\n",
                    "echo 'Installing AWS CLI'\n",
                    "pip install awscli --upgrade --user\n"
                ]]}}
            }
        }
    

    .bash_profile 正在使用正确更新文件 export PATH 最后,但安装 pip awscli pip公司 / aws /var/log/cloud-init.log 并且不会出现任何错误:

    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<=3.5.0,>=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<0.2.0,>=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>=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<=0.3.7,>=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<=3.12,>=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<3.0.0,>=2.1 (from botocore==1.5.76->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<1.0.0,>=0.7.1 (from botocore==1.5.76->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>=0.1.3 (from rsa<=3.5.0,>=3.1.2->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<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer<0.2.0,>=0.1.9
    ->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>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.5.76->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.
    

    2 回复  |  直到 9 年前
        1
  •  2
  •   Raf    9 年前

    AWS CLI pip documentation :

    将--user选项传递给python-m pip安装将只为当前用户安装一个包,而不是为系统的所有用户安装。

    我怀疑您正试图使用ec2用户运行它:如果您希望ec2用户和所有其他用户都可以访问它,请删除 --user

        2
  •  1
  •   Vineeth    9 年前

    添加到@Raf answer中,您可以使用以下命令为用户运行命令:,

    su - user -c 'shell command'
    

    对于你的情况,

    su - ec2-user 'pip install awscli --upgrade --user'