

# IAM DB 認証のトラブルシューティング
<a name="UsingWithRDS.IAMDBAuth.Troubleshooting"></a>

以下に、いくつかの一般的な IAM DB 認証に関する問題のトラブルシューティングのヒントと、IAM DB 認証の CloudWatch ログおよびメトリクスに関する情報を示します。

## CloudWatch Logs への IAM DB 認証エラーログのエクスポート
<a name="UsingWithRDS.IAMDBAuth.Troubleshooting.ErrorLogs"></a>

IAM DB 認証エラーログはデータベースホストに保存され、CloudWatch Logs アカウントでこれらのログをエクスポートできます。このページのログと修復方法を使用して、IAM DB 認証の問題をトラブルシューティングします。

コンソール、AWS CLI、および RDS API から CloudWatch Logs へのログエクスポートを有効にできます。コンソールの手順については、「[Amazon CloudWatch Logs へのデータベースログの発行](USER_LogAccess.Procedural.UploadtoCloudWatch.md)」を参照してください。

AWS CLI から DB インスタンスを作成するときに IAM DB 認証エラーログを CloudWatch Logs にエクスポートするには、次のコマンドを使用します。

```
aws rds create-db-instance --db-instance-identifier {{mydbinstance}} \
--region {{us-east-1}} \
--db-instance-class {{db.t3.large}} \
--allocated-storage {{50}} \
--engine {{postgres}} \
--engine-version {{16}} \
--port {{5432}} \
--master-username {{master}} \
--master-user-password {{password}} \
--publicly-accessible \
--enable-iam-database-authentication \
--enable-cloudwatch-logs-exports=iam-db-auth-error
```

AWS CLI から DB インスタンスを変更するときに IAM DB 認証エラーログを CloudWatch Logs にエクスポートするには、次のコマンドを使用します。

```
aws rds modify-db-instance --db-instance-identifier {{mydbinstance}} \
--region {{us-east-1}} \
--cloudwatch-logs-export-configuration '{"EnableLogTypes":["iam-db-auth-error"]}'
```

DB インスタンスが IAM DB 認証ログを CloudWatch Logs にエクスポートしているかどうかを確認するには、`describe-db-instances` コマンドの出力で `EnabledCloudwatchLogsExports` パラメータが `iam-db-auth-error` に設定されているかどうかを確認します。

```
aws rds describe-db-instances --region us-east-1 --db-instance-identifier {{mydbinstance}}
            ...
            
             "EnabledCloudwatchLogsExports": [
                "iam-db-auth-error"
            ],
            ...
```

## IAM DB 認証 CloudWatch メトリクス
<a name="UsingWithRDS.IAMDBAuth.Troubleshooting.CWMetrics"></a>

Amazon RDS は、IAM DB 認証に関するほぼリアルタイムのメトリクスを Amazon CloudWatch アカウントに配信します。次の表に、CloudWatch で使用可能な IAM DB 認証メトリクスを示します。


| メトリクス | 説明 | 
| --- | --- | 
| `IamDbAuthConnectionRequests` | IAM DB 認証で行われた接続リクエストの合計数。 | 
| `IamDbAuthConnectionSuccess` | 成功した IAM DB 認証リクエストの合計数。 | 
| `IamDbAuthConnectionFailure` | 失敗した IAM DB 認証リクエストの合計数。 | 
| `IamDbAuthConnectionFailureInvalidToken` | トークンが無効であるために失敗した IAM DB 認証リクエストの合計数。 | 
| `IamDbAuthConnectionFailureInsufficientPermissions` | ポリシーまたはアクセス許可が正しくないために失敗した IAM DB 認証リクエストの合計数。 | 
| `IamDbAuthConnectionFailureThrottling` | IAM DB 認証スロットリングにより失敗した IAM DB 認証リクエストの合計数。 | 
| `IamDbAuthConnectionFailureServerError` | IAM DB 認証機能の内部サーバーエラーにより失敗した IAM DB 認証リクエストの合計数。 | 

## 一般的な の問題と解決策
<a name="UsingWithRDS.IAMDBAuth.Troubleshooting.IssuesSolutions"></a>

 IAM DB 認証の使用時に、次の問題が発生することがあります。問題を解決するには、表の修復ステップを使用します。


| エラー | メトリクス | 原因 | ソリューション | 
| --- | --- | --- | --- | 
| `[ERROR] Failed to authenticate the connection request for user {{db_user}} because the provided token is malformed or otherwise invalid. (Status Code: 400, Error Code: InvalidToken)` | `IamDbAuthConnectionFailure`<br />`IamDbAuthConnectionFailureInvalidToken` | 接続リクエストの IAM DB 認証トークンが有効な SigV4a トークンではないか、正しくフォーマットされていません。 | アプリケーションでトークン生成戦略を確認します。場合によっては、トークンを有効なフォーマットで渡していることを確認してください。トークンを切り捨てる (または文字列形式が正しくない) と、トークンは無効になります。 | 
| `[ERROR] Failed to authenticate the connection request for user {{db_user}} because the token age is longer than 15 minutes. (Status Code: 400, Error Code:ExpiredToken)` | `IamDbAuthConnectionFailure`<br />`IamDbAuthConnectionFailureInvalidToken` | IAM DB 認証トークンの有効期限が切れています。トークンは 15 分間のみ有効です。 | アプリケーションでトークンキャッシュやトークン再利用ロジックを確認します。15 分を超えたトークンは再利用しないでください。 | 
| `[ERROR] Failed to authorize the connection request for user {{db_user}} because the IAM policy assumed by the caller 'arn:aws:sts::123456789012:assumed-role/ <RoleName>/ <RoleSession>' is not authorized to perform `rds-db:connect` on the DB instance. (Status Code: 403, Error Code:NotAuthorized)` | `IamDbAuthConnectionFailure`<br />`IamDbAuthConnectionFailureInsufficientPermissions` | このエラーの原因としては、以下が考えられます。[See the AWS documentation website for more details](http://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Troubleshooting.html) | アプリケーションで引き受ける IAM ロールおよび/またはポリシーを確認します。DB に接続するためのトークンを生成するには、同じポリシーを引き受けていることを確認してください。 | 
| `[ERROR] Failed to authorize the connection request for user {{db_user}} due to IAM DB authentication throttling. (Status Code: 429, Error Code: ThrottlingException)` | `IamDbAuthConnectionFailure`<br />`IamDbAuthConnectionFailureThrottling` | 短時間に DB への接続リクエストが多すぎます。IAM DB 認証のスロットリング制限は、1 秒あたり 200 接続です。 | IAM 認証を使用して新しい接続を確立する速度を下げます。アプリケーションで確立された接続を再利用するには、RDS Proxy を使用して接続プールを実装することを検討してください。 | 
| `[ERROR] Failed to authorize the connection request for user {{db_user}} due to an internal IAM DB authentication error. (Status Code: 500, Error Code: InternalError)` | `IamDbAuthConnectionFailure`<br />`IamDbAuthConnectionFailureThrottling` | IAM DB 認証で DB 接続の承認中に内部エラーが発生しました。 | https://aws.amazon.com/premiumsupport/ に連絡して問題を調査してください。 | 