2
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 5 years have passed since last update.

【rails tutorial 13.4.4】「ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key」エラーの対処法

Posted at

##経緯
railsチュートリアル「13.4.4 本番環境での画像アップロード」において、
AWSの「Simple Storage Service (S3)」との接続がうまくできませんでした。

本来スキップしても良い項目でしたが、
カリキュラム通り進めて
IAMの設定やS3との接続もできた(と思っていた)のですが

$ git push heroku
をすると、
「ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key」
及び
「remote:! Precompiling assets failed.」
というエラーが出てしまいましたので、その原因と対処法を記載します。

##結論
heroku config:setがされていなかった

AWSのS3を使う際には、登録したデータの紐付けが必要になります。
その際のコマンドに""(ダブルクォーテーション)を不必要に付けていたことが原因のようでした。

$ heroku config:set S3_ACCESS_KEY="ココに先ほどメモしたAccessキーを入力"
$ heroku config:set S3_SECRET_KEY="同様に、Secretキーを入力"
$ heroku config:set S3_BUCKET="Bucketの名前を入力"
$ heroku config:set S3_REGION="Regionの名前を入力"

↑こちらはチュートリアルから引用してきたコマンドです。
""は含まずに代入してください。

代入できたか確認するコマンドが以下になります

$ heroku config:get S3_ACCESS_KEY
$ heroku config:get S3_SECRET_KEY
$ heroku config:get S3_BUCKET
$ heroku config:get S3_REGION

setがgetになっただけです。
入力値が不安であれば確認の時に使ってください。

これで問題なく$ git push herokuはできるようになりました。

##別件の問題が
git push herokuをやりすぎてlimitいっぱいになってしまいました。
herokuはgit push回数に制限があるんですね。知りませんでした。

そこで、別のherokuをcreateしました。

git push herokuは無事できるようになりました。

しかし、
今度はアプリのsigninができなくなりました。

##signinできない原因
認証に使っているedit_account_activation_urlというリンクに入っている名前の中に古い方のheroku.app名が入っていました。

##対策
production環境のメール設定のhostを新しい方のherokuへ切り替える

config/environments/production.rb
 host = 'https://自分のherokuアプリ名.herokuapp.com/'

これで本番環境でのsigninができました。
ちょっと脱線してしまい、すみませんでした。

##まとめ
・$ heroku config:setコマンドには""は必要ない
・$ heroku config:getで反映できているか確認できる
・production.rbにherokuのhost情報を入れている

##参考
https://qiita.com/fuku_tech/items/b21e49ff49cb19f04838
https://310nae.com/es6-compile/
https://pg-happy.jp/rails-aws-s3-upload.html
https://qiita.com/kazukimatsumoto/items/a0daa7281a3948701c39

2
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
2
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?