cfn-init错误:无法检索远程元数据:无凭据

时间:2017-10-29 12:13:00

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

我有一个测试模板,可以使用cfn-init以及AWS::CloudFormation::AuthenticationAWS::CloudFormation::Init部分从S3存储桶下载单个非公开文件。

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

WARNING [2017-10-29 12:01:03,541] Unable to retrieve remote metadata : No credentials!
WARNING [2017-10-29 12:01:03,541] Unable to open local metadata : /var/cache/heat-cfntools/last_metadata
WARNING [2017-10-29 12:01:03,542] Unable to open local metadata : /var/lib/heat-cfntools/cfn-init-data
ERROR [2017-10-29 12:01:03,542] Unable to read any valid metadata!
ERROR [2017-10-29 12:01:03,542] Error processing metadata
Traceback (most recent call last):
  File "/usr/bin/cfn-init", line 68, in 
    metadata.cfn_init()
  File "/usr/lib/python2.7/dist-packages/heat_cfntools/cfntools/cfn_helper.py", line 1270, in cfn_init
    raise Exception("invalid metadata")
Exception: invalid metadata

完整模板 - 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"
}

1 个答案:

答案 0 :(得分: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"]]
                    }]
                }
            ]
        }
    }]
}

}