ruby - 使用 IAM 配置文件创建实例后无法访问 s3 存储桶

标签 ruby amazon-web-services amazon-s3 boto amazon-iam

我正在尝试从应用 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/

相关文章:

ruby - 为什么 RubyMine 2018.2 检测不到我的 gem ?

amazon-web-services - 部署 CloudFormation 模板,而不仅仅是变更集

python - 无效的实例 ID : An error occurred (InvalidInstanceId) when calling the SendCommand operation

file-upload - 如何使用node.js强大的库接收上传的文件并使用knox将其保存到Amazon S3?

postgresql - 将数据从 AWS S3 复制到 Aurora Postgres

ruby - Ruby 中是否有像 C 中那样的 "main"方法?

ruby-on-rails - 如何使用 ActiveSupport::Concern 继承类方法

ruby - 快速FTP服务器

amazon-web-services - aws cli elb/elbv2 - 如何按 DNSName 过滤负载均衡器?

amazon-web-services - 通过 cloudformation 在 s3 存储桶上启用对象日志记录