gpt4 book ai didi

python - cfn-init 退出并出现错误 - DistributionNotFound : pystache>=0. 4.0

转载 作者:行者123 更新时间:2023-12-03 07:34:47 25 4
gpt4 key购买 nike

运行我的云形成模板时,我有以下行:

/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",

关于python - cfn-init 退出并出现错误 - DistributionNotFound : pystache>=0. 4.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65215487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com