python - cfn-init 退出并出现错误 - DistributionNotFound: pystache>=0.4.0
问题描述
运行我的云形成模板时,我有一行:
/opt/aws/bin/cfn-init -v -s STACK_NAME --resource RESOURCE_NAME
执行此操作后(使用 CentOS),我得到以下控制台输出:
Traceback (most recent call last):
File "/opt/aws/bin/cfn-init", line 4, in <module>
import pkg_resources
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3007, in <module>
working_set.require(__requires__)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 728, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 626, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pystache>=0.4.0
在此行之前,我在用户数据中有以下内容:
yum update -y
yum install -y python-setuptools
yum install -y wget
mkdir -p /opt/aws/bin
wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
python -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-latest.tar.gz
yum install -y aws-cfn-bootstrap
我错过了安装步骤还是什么?
任何帮助都非常感谢!
编辑
下面是完整的模板。(虽然所使用的 AMI 是自定义 CentOS 的)。
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description": "Description",
"Parameters" : {
"InstanceTypeParam" : {
"Type" : "String",
"Default" : "t3.large",
"AllowedValues": [ "t3.small", "t3.medium", "t3.large" ],
"Description": "Description"
},
"KeyNameParam" : {
"Type": "AWS::EC2::KeyPair::KeyName",
"Description" : "Description"
},
"SubnetIDParam" : {
"Type" : "AWS::EC2::Subnet::Id",
"Description" : "Description",
"Default" : "default"
},
"SecurityGroupIDParam" : {
"Type" : "AWS::EC2::SecurityGroup::Id",
"Description" : "Description",
"Default" : "default"
},
"InstanceNameParam" : {
"Type" : "String",
"Description" : "Description"
}
},
"Resources" : {
"EC2" : {
"Type": "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"commands" : {
"a" : {
"command" : "/bin/echo \"Executing AWS::CloudFormation::Init commands\" >> /tmp/testfile.txt"
},
"b" : {
"command" : "more commands..."
}
}
}
}
},
"Properties": {
"ImageId": "ami-customAMIID",
"InstanceType": {"Ref": "InstanceTypeParam"},
"KeyName": {"Ref": "KeyNameParam"},
"SecurityGroupIds": [{"Ref": "SecurityGroupIDParam"}],
"SubnetId": {"Ref": "SubnetIDParam"},
"IamInstanceProfile" : "AnIAMInstanceProfile",
"BlockDeviceMappings" : [
{
"DeviceName" : "/dev/sda1",
"Ebs" : {
"DeleteOnTermination" : "true",
"VolumeSize" : "30"
}
}
],
"Tags" : [
{"Key" : "Name", "Value" : {"Ref" : "InstanceNameParam"} }
],
"UserData": { "Fn::Base64": { "Fn::Join": ["\n", [
"Content-Type: multipart/mixed; boundary=\"//\"",
"MIME-Version: 1.0",
"",
"--//",
"Content-Type: text/cloud-config; charset=\"us-ascii\"",
"MIME-Version: 1.0",
"Content-Transfer-Encoding: 7bit",
"Content-Disposition: attachment; filename=\"cloud-config.txt\"",
"",
"#cloud-config",
"cloud_final_modules:",
"- [scripts-user, always]",
"",
"--//",
"Content-Type: text/x-shellscript; charset=\"us-ascii\"",
"MIME-Version: 1.0",
"Content-Transfer-Encoding: 7bit",
"Content-Disposition: attachment; filename=\"userdata.txt\"",
"",
"#!/bin/bash",
"# If UserData hasn't yet been installed then install everything",
"if [[ -z \"${USERDATA_INSTALLED}\" ]]; then",
"/bin/echo \"Entering if statement\" >> /tmp/testfile.txt",
"yum update -y",
"yum install -y python-setuptools",
"yum install -y wget",
"mkdir -p /opt/aws/bin",
"wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz",
"python -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-latest.tar.gz",
"/bin/echo \"Successfully installed aws-cfn-bootstrap\" >> /tmp/testfile.txt",
"yum install -y aws-cfn-bootstrap",
{ "Fn::Join" : ["",[ "/opt/aws/bin/cfn-init -v -s ", { "Ref" : "AWS::StackName" }, " --resource EC2" ]]},
"/bin/echo \"Exiting if statement\" >> /tmp/testfile.txt",
"fi"
]]
}}
}
}
}
}
解决方案
有确切的错误。通过使用“pip install”而不是“easy_install”修复:
-
"easy_install aws-cfn-bootstrap-latest\n",
-
"pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
推荐阅读
- html - Ionic:如何在 Shadow DOM 中更改 span.button-inner 的 CSS
- docker - Pulumi 不执行 Kubernetes Pod 的优雅关闭
- sql-server - 仅 6 分钟后在 SQL Server 超时后重建索引。超时设置为 60 分钟
- javascript - 在调整 Mat-table 大小时检测滚动条是否可见
- node.js - 尝试在 graphql 中检索模式时出现问题
- sql - 从同一列中选择多个值和具有一个特定值的记录数
- flutter - Flutter 应用程序在启动屏幕后短暂显示黑屏,在主页显示之前
- flutter - 抽象类的 setState 替代方案?
- r - 为什么我没有得到由其他分类变量分组的两个数字列的计数,只有 tidyverse?
- asp.net-core - 如何通过控制器将参数传递给策略中使用的授权处理程序