LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】Aws::S3::Errors::RequestTimeTooSkewed への対処

Last updated at Posted at 2022-05-03

S3へのリクエストタイムが違いシードが流せない

Railsの本番環境でシードデータを入れる時に、
S3とのtimeがかけ離れているというニュアンスのメッセージが出現した。

[sirius@ip-10-0-11-191 diary_app]$ rails db:seed RAILS_ENV=production
Start inserting first seed "user" ...
rails aborted!
Aws::S3::Errors::RequestTimeTooSkewed: The difference between the request time and the current time is too large.

EC2インスタンス上ではJST(日本標準時)を指定しているので、dateでそれ確かめてみると、たしかに、実際の時間が10:00なのにインスタンス40分近くずれていることがわかった。

これがシードデータを流すときに、S3バケットにアクセスした際に時間差がおおきすぎるのでエラーが生じたのだろう。

[sirius@ip-10-0-11-191 diary_app]$ date
2022年  5月  3日 火曜日 10:45:36 JST

おそらくサーバーが一定の時間停止していたことが原因でズレたと推測するが、どのタイミングでずれたのか調査中である。

解決策(サーバー再起動)

解決策はとても簡単で、EC2サーバーを立ち上げ直せばうまくいく。
AWSダッシュボードより、EC2インスタンスを停止してから⇨開始して起動し直す。
スクリーンショット 2022-05-03 10.46.01.png

そうしてEC2上で

[sirius@ip-10-0-11-191 diary_app]$ date
2022年  5月  3日 火曜日 10:10:00 JST

とすると40分先に進んでいた時刻が戻っていることがわかる。

これでrails db:seed RAILS_ENV=productionとするとうまくいった。

参考ページ

Rails の S3 連携で Internal Server Error となる

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