amazon-web-services - cfn-init 错误 : Unable to retrieve remote metadata : No credentials

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

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

这在 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

The full template - https://pastebin.com/e072d5GF.

I found a similar question on Launchpad, but it has no answer.

Edit: This is the output from 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"
}

最佳答案

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

将其添加到资源中,并更改 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"]]
                    }]
                }
            ]
        }
    }]
}

}

关于amazon-web-services - cfn-init 错误 : Unable to retrieve remote metadata : No credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47000035/

相关文章:

linux - 无法按名称调用系统调用

linux - 将文件移动到它们自己的目录中

ios - 视频,上传到S3存储桶,不在iOS应用程序中通过url播放

amazon-web-services - 如何让Redisson Semaphore自动释放

geolocation - AWS 数据中心位置在哪里列出?

python - 尝试在 Ubuntu 16.04 上运行 pip3 时出错

java - 从 Spring MVC 端点流式传输动态图像而不将其保存在内存中

javascript - nodejs如何从aws s3存储桶获取JSON而不是Buffer

swift - s3 图像上传的 Swift 中的 AWS Appsync 工作示例?

amazon-web-services - AWS Elasticsearch快照-由于服务链接的角色而导致的IAM问题