

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 確認後の Lambda トリガー
<a name="user-pool-lambda-post-confirmation"></a>

Amazon Cognito は、サインアップしたユーザーがユーザーアカウントを確認した後にこのトリガーを呼び出します。投稿確認 Lambda 関数では、カスタムメッセージを送信したり、カスタム API リクエストを追加したりできます。たとえば、外部システムにクエリを実行して、ユーザーに追加の属性を入力できます。Amazon Cognito は、管理者認証情報を使用して作成したユーザーではなく、ユーザープールにサインアップしたユーザーに対してのみこのトリガーを呼び出します。

リクエストには、確認されたユーザーの現在の属性が含まれています。ユーザープールは、[ConfirmSignUp](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ConfirmSignUp.html)、[AdminConfirmSignUp](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminConfirmSignUp.html)、[ConfirmForgotPassword](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ConfirmForgotPassword.html) に対して確認後の関数を呼び出します。このトリガーは、ユーザーが[マネージドログイン](cognito-user-pools-managed-login.md)でサインアップまたはパスワードのリセットを確認したときにも実行されます。

**Topics**
+ [確認後の Lambda トリガーのパラメータ](#cognito-user-pools-lambda-trigger-syntax-post-confirmation)
+ [確認後の例](#aws-lambda-triggers-post-confirmation-example)

## 確認後の Lambda トリガーのパラメータ
<a name="cognito-user-pools-lambda-trigger-syntax-post-confirmation"></a>

Amazon Cognito がこの Lambda 関数に渡すリクエストは、以下のパラメータと Amazon Cognito がすべてのリクエストに追加する[共通パラメータ](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-working-with-lambda-triggers.html#cognito-user-pools-lambda-trigger-syntax-shared)を組み合わせたものです。

------
#### [ JSON ]

```
{
    "request": {
            "userAttributes": {
                "string": "string",
                . . .
            },
            "clientMetadata": {
            	"string": "string",
            	. . .
            }
        },
    "response": {}
}
```

------

### 確認後のリクエストパラメータ
<a name="cognito-user-pools-lambda-trigger-syntax-post-confirmation-request"></a>

**userAttributes**  
ユーザー属性を表す 1 つ以上のキーバリューペア。

**clientMetadata**  
確認後のトリガーに指定する Lambda 関数へのカスタム入力として提供できる 1 つ、または複数のキー/値ペア。このデータは、[AdminConfirmSignUp](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminConfirmSignUp.html)、[ConfirmForgotPassword](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ConfirmForgotPassword.html)、[ConfirmSignUp](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ConfirmSignUp.html)、および [SignUp](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_SignUp.html) の API アクションで ClientMetadata パラメータを使用することによって Lambda 関数に渡すことができます。

### 確認後のレスポンスパラメータ
<a name="cognito-user-pools-lambda-trigger-syntax-post-confirmation-response"></a>

レスポンスで返される追加の情報は想定されていません。

## 確認後の例
<a name="aws-lambda-triggers-post-confirmation-example"></a>

この Lambda 関数の例では、Amazon SES を使用してユーザーに確認 E メールメッセージを送信します。詳細については、[Amazon Simple Email Service デベロッパーガイド](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/)を参照してください。

------
#### [ Node.js ]

```
// Import required AWS SDK clients and commands for Node.js. Note that this requires
// the `@aws-sdk/client-ses` module to be either bundled with this code or included
// as a Lambda layer.
import { SES, SendEmailCommand } from "@aws-sdk/client-ses";
const ses = new SES();

const handler = async (event) => {
  if (event.request.userAttributes.email) {
    await sendTheEmail(
      event.request.userAttributes.email,
      `Congratulations ${event.userName}, you have been confirmed.`,
    );
  }
  return event;
};

const sendTheEmail = async (to, body) => {
  const eParams = {
    Destination: {
      ToAddresses: [to],
    },
    Message: {
      Body: {
        Text: {
          Data: body,
        },
      },
      Subject: {
        Data: "Cognito Identity Provider registration completed",
      },
    },
    // Replace source_email with your SES validated email address
    Source: "<source_email>",
  };
  try {
    await ses.send(new SendEmailCommand(eParams));
  } catch (err) {
    console.log(err);
  }
};

export { handler };
```

------

Amazon Cognito は Lambda 関数にイベント情報を渡します。関数はレスポンスで、同じイベントオブジェクトを変更と共に Amazon Cognito に返します。Lambda コンソールで、Lambda トリガーに関連するデータを使用したテストイベントをセットアップできます。以下は、このコードサンプルのテストイベントです。

------
#### [ JSON ]

```
{
    "request": {
        "userAttributes": {
            "email": "user@example.com",
            "email_verified": true
        }
    },
    "response": {}
}
```

------