如何針對 Amazon Cognito 中匯入程序的常見錯誤進行疑難排解?

2 分的閱讀內容
0

我想要針對 Amazon Cognito 中匯入程序的常見錯誤進行疑難排解。

簡短描述

以下是與 Amazon Cognito 匯入程序相關聯的常見錯誤:

使用者移轉 AWS Lambda 觸發匯入錯誤:

  • AccessDeniedException
  • UserCodeSyntaxError
  • ResourceNotFoundException
  • ImportModuleError

CSV 檔案匯入錯誤:

  • 非預期標頭
  • 失敗/跳過的使用者
  • 匯入作業已過期
  • 無效的屬性值
  • CloudWatch Logs 角色缺少許可

解決方案

當您使用 CSV 檔案或 Lambda 觸發在 Amazon Cognito 中進行匯入時,錯誤會記錄在 Amazon CloudWatch Logs。在您的 AWS 帳戶中查看並搜尋這些錯誤。

使用者移轉 Lambda 觸發匯入錯誤

AccessDeniedException:

當 Lambda 角色缺少執行 Amazon Cognito 動作的 AWS Identity and Access Management (IAM) 許可時,就會記錄此錯誤。例如,AdminInitiateAuthAccessDeniedException 錯誤類似於以下內容:

An error occurred (AccessDeniedException) when calling the AdminInitiateAuth operation: User: arn:aws:sts::ACCOUNT_ID:assumed-role/TestingMigration-role/TestingMigration is not authorized to perform: cognito-idp:AdminInitiateAuth on resource: arn:aws:cognito-idp:eu-central-1:ACCOUNT_ID:userpool/eu-central-1_YYYYOOOO
    because no identity-based policy allows the cognito-idp:AdminInitiateAuth action

若要解決 AccessDeniedException 錯誤,請執行以下動作:

  1. 開啟 IAM 主控台
  2. 在導覽窗格中,選擇 Roles (角色) 並且尋找 Lambda 執行角色。
  3. 針對 IAM 角色選擇 Permissions (許可) 標籤。
  4. 展開許可政策以檢視與使用者關聯的許可。
  5. 請確定政策包含下列參數:
    Actions (動作) 清單中的 cognito-idp:AdminInitiateAuth
    允許****效果
  6. 如果政策中不包含這些參數,則更新政策以包含這些參數。
    -或-
    建立遵循參數的新政策,並將政策附加到 IAM 角色。如需詳細資訊,請參閱編輯客戶受管政策 (主控台)

UserCodeSyntaxError:

在您的 Lambda 程式碼中發現程式碼問題時,就會記錄此錯誤。例如,縮進問題。

UserCodeSyntaxError 錯誤類似於以下內容:

[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'lambda_function': unexpected indent

若要解決此錯誤,請務必檢查程式碼中的正確語法使用方式。

ResourceNotFoundException:

在您的 AWS 帳戶或 AWS 區域中找不到 Lambda 程式碼中參照的資源時,就會記錄此錯誤。例如,Amazon Cognito 應用程式用戶端。

ResourceNotFoundException 錯誤類似於以下內容:

[ERROR] ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the AdminInitiateAuth operation: User pool client 52rXXXXXXXXXXXXXXXXXXge does not exist.

若要解決此錯誤,請確認有問題的資源存在於您的 AWS 帳戶和區域中。然後,確認您已在 Lambda 程式碼中正確指定 ID、名稱或 Amazon Resource Name (ARN)。

ImportModuleError:

當您嘗試匯入或參考不存在於 Lambda 程式碼中的模組時,會記錄此錯誤。

ImportModuleError 錯誤類似於以下內容:

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named lambda_function

若要解決此錯誤,請確認您嘗試在程式碼中匯入的模組不包含任何錯別字或不存在的模組參照。

CSV 檔案匯入錯誤

Unexpected headers:

在您的 CSV 檔案中缺少標頭或格式錯誤時,會記錄此錯誤。

非預期標頭錯誤類似於以下內容:

The header in the CSV file does not match the expected headers. Use the GetCSVHeader API to get the expected headers.

若要解決此錯誤,請執行下列動作:

執行下列命令以取得正確標頭的清單,其中 USER_POOL_ID 是您將使用者匯入到其中的使用者集區:

aws cognito-idp get-csv-header --user-pool-id "USER_POOL_ID"

您也可以使用 Amazon Cognito 主控台下載 CSV 檔案標頭。如需詳細資訊,請參閱下載 CSV 檔案標頭 (主控台)

失敗或略過的使用者:

有重複使用者參考問題時,或您的 CSV 檔案中缺少必要欄位時,會記錄此錯誤。例如,email_verifiedcognito:mfa_enabled

失敗或略過的使用者錯誤看起來類似下列內容:

Too many users have failed or been skipped during the import.

若要解決此錯誤,請務必從 CSV 檔案中移除重複的使用者,並確定已指定必要的屬性。如需詳細資訊,請參閱建立使用者匯入 CSV 檔案

匯入作業已過期:

當您建立作業卻未在 24-48 小時內啟動作業時,會記錄此錯誤。

匯入作業已過期錯誤類似於以下內容:

The user import job has expired.

若要解決此問題,請使用下列命令啟動使用者匯入作業:

aws cognito-idp start-user-import-job --user-pool-id "USER_POOL_ID" --job-id "JOB_ID"

您也可以使用 Amazon Cognito 主控台啟動作業。如需詳細資訊,請參閱從 CSV 檔案匯入使用者 (主控台)

**注意:**每個帳戶一次只能啟用一個匯入作業。

無效的屬性值:

此錯誤表示針對 CSV 檔案中的屬性指定了無效的值。

無效的屬性值錯誤看起來類似下列內容:

The User Record contains an invalid value for [attribute].

若要解決這個問題,請檢查為屬性指定的值。如需有關屬性值的詳細資訊,例如電話號碼的正確格式,請參閱使用者集區屬性

CloudWatch Logs 角色缺少許可:

此錯誤表示為 CSV 匯入程序指定的 CloudWatch Logs 角色具有以下其中一個問題:

  • 缺少許可,例如建立日誌群組或串流。
  • 與主體的信任關係政策無效。

CloudWatch Logs 角色缺少許可錯誤看起來類似下列內容:

設定的 CloudWatch Logs 角色缺少許可或具有無效的信任政策。

若要解決此問題,請確定您具有允許 CloudWatch 動作的身分識別許可。另外,請確定在信任關係政策中允許 cognito-idp.amazonaws.com 做為服務主體。如需詳細資訊,請參閱建立 CloudWatch Logs IAM 角色


AWS 官方
AWS 官方已更新 1 年前