我正在尝试从应用 IAM 配置文件创建的实例访问一些 s3 存储桶,该配置文件允许完全访问这些 s3 存储桶。我能够使用 aws cli
执行所需的操作。但是,我的应用程序是用 Ruby 编写的,并使用了 fog
gem。使用雾,我无法访问那些桶。我得到的只是拒绝访问。此外,我还抓取了所需的 key :
aws_access_key_id=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep 访问 key ID |剪切-d':'-f2 | sed 's/[^0-9A-Z]*//g'`
aws_secret_access_key=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile} | grep secret 访问 key |剪切-d':'-f2 | sed 's/[^0-9A-Za-z/+=]*//g'`
并尝试访问存储桶。再次,访问被拒绝。
有什么我应该错过的吗?
最佳答案
除了访问 key 和 secret 访问 key ,临时凭证(例如实例元数据提供的凭证)也有 session token - 没有 token ,凭证无效。
当前版本的 fog/fog-aws 支持为您获取实例凭证,例如
storage = Fog::Storage::AWS.new(region: "eu-west-1", use_iam_profile:true)
这还将在凭据过期之前重新获取凭据
关于ruby - 使用 IAM 配置文件创建实例后无法访问 s3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30658377/