简体   繁体   English

cfn-init 退出并出现错误 - DistributionNotFound: pystache>=0.4.0

[英]cfn-init exiting with error - DistributionNotFound: pystache>=0.4.0

When running my cloud formation template I have the line:运行我的云形成模板时,我有一行:

/opt/aws/bin/cfn-init -v -s STACK_NAME --resource RESOURCE_NAME

I get the following console output after this is executed (using CentOS):执行此操作后(使用 CentOS),我得到以下控制台 output:

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

In the run up to this line I havethe following in the user data:在此行之前,我在用户数据中有以下内容:

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

Am I missing an install step or something?我错过了安装步骤还是什么?

Any help is much appriciated!任何帮助都非常感谢!

EDIT编辑

Below is the full template.下面是完整的模板。 (Although the AMI being used is a custom CentOS one). (虽然使用的 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"
                    ]]
                }}
            }
        }
    }
}

Had the exact error.有确切的错误。 Fixed by using "pip install" instead of "easy_install":通过使用“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",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM