Amazon-Cloudformation

在 CentOS 8 上安裝 cfn-bootstrap 實用程序的最佳方法

  • May 7, 2021

我正在 AWS 中處理基於 CentOS 8 的實例/啟動配置,並希望使用 cfn-init 來管理一些設置/配置步驟。

但是,我發現提供的 RPM 沒有部署,因為 Python2 和 Python3 的打包方式不同,以至於 AWS 提供的 RPM 找不到它的依賴項。

我用來安裝的命令是:yum install -y https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.amzn1.noarch.rpm

這會導致以下錯誤:

Error: 
Problem: conflicting requests
 - nothing provides python >= 2.6 needed by aws-cfn-bootstrap-1.4-34.noarch
 - nothing provides python-setuptools needed by aws-cfn-bootstrap-1.4-34.noarch
 - nothing provides python-daemon needed by aws-cfn-bootstrap-1.4-34.noarch
 - nothing provides pystache needed by aws-cfn-bootstrap-1.4-34.noarch

我懷疑這是因為 CentOS <= 7 中的 python 現在是 CentOS8 中的 python2。

在這種情況下安裝這些工具的最佳方式是什麼?

因此,最後我解壓了 tarball 並通過 UserData 腳本執行安裝。這是通過調整現有指南來完成的,以了解如何通過 CLI 進行操作

這會導致腳本很長,並且下面的版本僅安裝 Python2,因為在 Python3 上執行 AWS 工具時存在一些問題(對於我的案例,我只需要 Python,否則我會想辦法解決這個問題)。

     "UserData" :  {"Fn::Base64" : {
       "Fn::Join" : ["", [
         "#!/bin/bash\n",
         "mkswap /dev/nvme1n1\n",
         "swapon /dev/nvme1n1\n",
         "yum -y update\n",
         "yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm\n",
         "yum -y install python2 python2-pip\n",
         "pip2 install pystache\n",
         "ln -s /usr/bin/python2 /usr/bin/python\n",
         "curl -O https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
         "tar xvf aws-cfn-bootstrap-latest.tar.gz\n",
         "cd aws-cfn-bootstrap-*/\n",
         "python setup.py build\n",
         "python setup.py install\n",
         "mkdir -p /opt/aws/bin\n",
         "ln -s /usr/init/redhat/cfn-hup /etc/init.d/cfn-hup\n",
         "chmod 775 /usr/init/redhat/cfn-hup\n",
         "ln -s /usr/bin/cfn-hup /opt/aws/bin/cfn-hup\n",
         "ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal\n",
         "ln -s /usr/bin/cfn-init /opt/aws/bin/cfn-init\n",
         "ln -s /usr/bin/cfn-get-metadata /opt/aws/bin/cfn-get-metadata\n",
         "ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal\n",
         "ln -s /usr/bin/cfn-send-cmd-event /opt/aws/bin/cfn-send-cmd-event\n",
         "ln -s /usr/bin/cfn-send-cmd-result /opt/aws/bin/cfn-send-cmd-result\n",
         "/opt/aws/bin/cfn-init -v",
           " --stack ", { "Ref" : "AWS::StackName" },
           " --resource VPNServerLaunchTemplate",
           " --region ", { "Ref" : "AWS::Region" }, 
           "\n"
       ]]
     }}
   }

編輯- 顯然有一個 Python3 兼容版本可以從https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz下載。有關更多詳細資訊,請查看AWS 文件

引用自:https://serverfault.com/questions/1053824