0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Rails】本番環境のECSからS3へアクセスできないを解決【AWS】

Posted at

やりたいこと

本番環境でRailsからS3へファイルアップロードする時のエラーを解決したい。

環境

  • rails 6.14
    • gem 'aws-sdk-rails'
    • gem 'aws-sdk-s3', '~> 1'
  • ECS(Fargate)

結論

ECSの資格情報をRailsに与えることで解決。
app/controllers/rails_controller.rb内の記述を以下に書き換える。

app/controllers/rails_controller.rb(修正後)
s3 = Aws::S3::Resource.new(
      region: @region,
      credentials: Aws::ECSCredentials.new
    )
app/controllers/rails_controller.rb(修正前)
s = Aws::S3::Resource.new(
      region: @region,
      credentials: Aws::Credentials.new(
          ENV['AWS_ACCESS_KEY'],
          ENV['AWS_SECRET_KEY']
       )
    )
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?