【问题标题】:cfn-init error: Unable to retrieve remote metadata : No credentialscfn-init 错误:无法检索远程元数据:没有凭据
【发布时间】:2017-10-29 12:13:00
【问题描述】:

我有一个测试模板,它使用 cfn-initAWS::CloudFormation::AuthenticationAWS::CloudFormation::Init 部分从 S3 存储桶下载单个非公共文件。

这在 Amazon AMI 上成功运行,但在 Ubuntu AMI 上失败并出现以下错误:

警告 [2017-10-29 12:01:03,541] 无法检索远程元数据:没有凭据!
警告 [2017-10-29 12:01:03,541] 无法打开本地元数据:/var/cache/heat-cfntools/last_metadata
警告 [2017-10-29 12:01:03,542] 无法打开本地元数据:/var/lib/heat-cfntools/cfn-init-data
错误 [2017-10-29 12:01:03,542] 无法读取任何有效的元数据!
错误 [2017-10-29 12:01:03,542] 处理元数据时出错
回溯(最近一次通话最后):
  文件“/usr/bin/cfn-init”,第 68 行,在
    metadata.cfn_init()
  cfn_init 中的文件“/usr/lib/python2.7/dist-packages/heat_cfntools/cfntools/cfn_helper.py”,第 1270 行
    引发异常(“无效元数据”)
例外:无效的元数据

完整模板 - https://pastebin.com/e072d5GF

我发现了一个类似的问题on Launchpad,但没有答案。

编辑:这是curl 169.254.169.254/latest/meta-data/iam/info/的输出:

{
  "Code" : "InstanceProfileNotFound",
  "Message" : "Instance Profile with Id AIPAJWC744OTCCS55JMTW cannot be found.  Please see documentation at http://docs.amazonwebservices.com/IAM/latest/UserGuide/RolesTroubleshooting.html.",
  "LastUpdated" : "2017-10-29T12:26:01Z"
}

【问题讨论】:

    标签: amazon-web-services ubuntu amazon-s3 amazon-cloudformation


    【解决方案1】:

    您正在指定一个名为“s3access”的角色,但您并未声明它。如果它不存在,则需要创建它。

    在 Resources 中添加这个,并更改 Bucket_Name(2 个条目)和 Path_Name(1 个条目)以匹配您的配置:

    "s3access": {
    "Type": "AWS::IAM::Role",
    "Properties": {
        "AssumeRolePolicyDocument": {
            "Version": "2012-10-17",
            "Statement": [{
                "Effect": "Allow",
                "Principal": {
                    "Service": ["ec2.amazonaws.com"]
                },
                "Action": ["sts:AssumeRole"]
            }]
        },
        "Path": "/",
        "Policies": [{
            "PolicyName": "S3_Read",
            "PolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [{
                        "Effect": "Allow",
                        "Action": "s3:GetObject",
                        "Resource": [{
                            "Fn::Join": ["", ["arn:aws:s3:::", "Bucket_Name", "/Path_Name/*"]]
                        }, ]
                    },
                    {
                        "Effect": "Allow",
                        "Action": "s3:ListBucket",
                        "Resource": [{
                            "Fn::Join": ["", ["arn:aws:s3:::", "Bucket_Name"]]
                        }]
                    }
                ]
            }
        }]
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2016-10-24
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      • 2018-11-22
      • 1970-01-01
      相关资源
      最近更新 更多