无法为 Rails 项目设置凭据以将 S3 与 IAM 角色一起使用
Failing to set credentials for Rails project to use S3 with IAM role
我正在使用 ActiveStorage 将文件上传到 S3 存储桶。如果有人熟悉 Heroku Bucketeer 附加组件,我用了一段时间来测试 ActiveStorage 以及在存储桶中上传和下载文件。
出于某些原因,我必须使用 IAM 角色将凭据设置为只有存储桶名称和区域的新 Amazon S3 存储桶。在 ActiveStorage RubyOnRails 指南中说:
If you want to use environment variables, standard SDK configuration files, profiles, IAM instance profiles or task roles, you can omit the access_key_id, secret_access_key, and region keys in the example above.
不过我得到
(Aws::Sigv4::Errors::MissingCredentialsError)
- :access_key_id and :secret_access_key
- :credentials
- :credentials_provider
我的 storage.yml 看起来像这样:
amazon:
service: S3
bucket: <%= ENV['BUCKET_NAME'] %>
region: <%= ENV['AWS_REGION'] %>
我在development.rb和production.rb
中都写了config.active_storage.service = :amazon
我已经尝试过 ,但没有成功。
我正在使用 Rails 5.2.4.1、Ruby 2.6.3,并且在 Gemfile
中有 gem 'aws-sdk'
特别是在进行开发工作时,您需要提供 access_key_id
和 secret_access_key
。您可以通过输入 storage.yml
:
来做到这一点
amazon:
service: S3
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
bucket: <%= ENV['BUCKET_NAME'] %>
region: <%= ENV['AWS_REGION'] %>
或者,确保您已设置正确的环境变量,以启用对您的 aws 凭据的隐式查找,如 AWS 所指定。即设置环境变量AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY
我正在使用 ActiveStorage 将文件上传到 S3 存储桶。如果有人熟悉 Heroku Bucketeer 附加组件,我用了一段时间来测试 ActiveStorage 以及在存储桶中上传和下载文件。
出于某些原因,我必须使用 IAM 角色将凭据设置为只有存储桶名称和区域的新 Amazon S3 存储桶。在 ActiveStorage RubyOnRails 指南中说:
If you want to use environment variables, standard SDK configuration files, profiles, IAM instance profiles or task roles, you can omit the access_key_id, secret_access_key, and region keys in the example above.
不过我得到
(Aws::Sigv4::Errors::MissingCredentialsError)
- :access_key_id and :secret_access_key
- :credentials
- :credentials_provider
我的 storage.yml 看起来像这样:
amazon:
service: S3
bucket: <%= ENV['BUCKET_NAME'] %>
region: <%= ENV['AWS_REGION'] %>
我在development.rb和production.rb
中都写了config.active_storage.service = :amazon
我已经尝试过
我正在使用 Rails 5.2.4.1、Ruby 2.6.3,并且在 Gemfile
中有gem 'aws-sdk'
特别是在进行开发工作时,您需要提供 access_key_id
和 secret_access_key
。您可以通过输入 storage.yml
:
amazon:
service: S3
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
bucket: <%= ENV['BUCKET_NAME'] %>
region: <%= ENV['AWS_REGION'] %>
或者,确保您已设置正确的环境变量,以启用对您的 aws 凭据的隐式查找,如 AWS 所指定。即设置环境变量AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY