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

AWS Cognitoとバックエンドの設定に関するトラブル解決メモ

Posted at

AWS Cognitoとバックエンドの設定に関するトラブル解決メモ

背景

バックエンドAPIで認証エラー (401 Unauthorized) が発生しました。このエラーは、環境変数に必要なCognitoの設定が不足していたことが原因でした。


問題の原因

以下の2つの環境変数が .env ファイルに設定されていませんでした:

  • COGNITO_USER_POOL_ID
  • COGNITO_USER_POOL_CLIENT_ID

これらは、AWS Cognitoを使用した認証の必須項目です。


解決手順

1. 必要なCognito情報を取得

AWS管理画面にログインして、以下を取得します

  • User Pool ID(例:ap-northeast-1_example123
  • App Client ID(例:1a2b3c4d5e6f7g8h9i0j

2. .envファイルに追記

バックエンドの .env ファイルに以下の内容を追加します:

COGNITO_USER_POOL_ID=ap-northeast-1_example123
COGNITO_USER_POOL_CLIENT_ID=1a2b3c4d5e6f7g8h9i0j

3. Dockerコンテナの再起動

変更を反映するため、Dockerを再起動します:

docker-compose down
docker-compose up -d

4. 動作確認

以下のコマンドでAPIが正常に動作するか確認します:

curl http://localhost:13000/api

メモ

AWS Cognitoの設定は、環境変数に正しく設定すること。
Docker再起動は、環境変数の変更後に必須。
必要な情報が不明な場合は、管理者に確認。

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