LoginSignup
4
0

More than 3 years have passed since last update.

AWS Cognito トリガーを使ってサインアップ・サインインのログを取る

Posted at

目的

Cognitoで認証システムを構築したをWebサイトに対して、サインアップやサインインがどのくらい行われたのかログを取りたかった。

トリガー

image.png

上記のようにlambda関数を指定する。すると以下のようなログがCloudWatch Logsに出力される。

サインアップ前・・・サインアップ時にユーザーが送信する情報が含まれる

{
    'version': '1',
    'region': 'ap-northeast-1',
    'userPoolId': 'ap-northeast-1_XXXXXXXXX',
    'userName': 'test-user-29',
    'callerContext': {
        'awsSdkVersion': 'aws-sdk-js-2.6.4',
        'clientId': 'xxxxxxxxxxxxxxxxxxxxxxxxx'
    },
    'triggerSource': 'PreSignUp_SignUp',
    'request': {
        'userAttributes': {
            'email': 'xxxxxxxxxxxx@sample.com'
        },
        'validationData': None
    },
    'response': {
        'autoConfirmUser': False,
        'autoVerifyEmail': False,
        'autoVerifyPhone': False
    }
}

認証前・・・サインイン時にユーザーが送信する情報が含まれる

{
    'version': '1',
    'region': 'ap-northeast-1',
    'userPoolId': 'ap-northeast-1_XXXXXXXXX',
    'userName': 'test-user-13',
    'callerContext': {
        'awsSdkVersion': 'aws-sdk-js-2.6.4',
        'clientId': 'xxxxxxxxxxxxxxxxxxxxxxxxx'
    },
    'triggerSource': 'PreAuthentication_Authentication',
    'request': {
        'userAttributes': {
            'sub': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
            'email_verified': 'true',
            'cognito:user_status': 'CONFIRMED',
            'email': 'xxxxxxxxxxxx@sample.com'
        },
        'validationData': {},
        'userNotFound': False
    },
    'response': {}
}

Lambda関数

画像にあるlambda関数は以下の通り。

def lambda_handler(event, context):
    print(event)
    return event

参考記事

4
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
4
0