AWS識別ユーザプールをDynamoDBに保存する
0.入る
Cognito userpoolは、ユーザ情報を含むディレクトリです.この情報をDBにエクスポートする機能はなく,会員加入時にPost confirm lambdaをトリガし,Lambdaがユーザ情報をDBに保存することを実現した.
CognitoユーザープールのLambdaについては、正式な書類を参照してください.
1. Create User pool
User Poolは既に作成されており、属性は以下の通りです.
ユーザID、Email、name、subからなる.
2. Create DynamoDB Table
ユーザーIDをパーティションキーとして使用するテーブルを作成します.
すべての設定はデフォルトで使用され、パーティションキーはIDに設定され、タイプはStringに設定され、生成されます.
3. Create Lambda
データベース内のLambdaを作成します.LambdaコンソールにAddUserFuncというRamdaを作成し、次のコードを記述しました.
index.jsvar aws = require('aws-sdk');
var ddb = new aws.DynamoDB({apiVersion: '2012-10-08'});
exports.handler = async (event, context) => {
console.log(event);
let date = new Date();
// If the required parameters are present, proceed
if (event.request.userAttributes.sub) {
// -- Write data to DDB
let ddbParams = {
Item: {
'id': {"S": event.request.userAttributes.sub},
'__typename': {"S": 'User'},
'username': {"S": event.userName},
'name': {"S": event.request.userAttributes.name},
'email': {"S": event.request.userAttributes.email}
},
TableName: "sampleUserPoolTbl"
};
// Call DynamoDB
try {
await ddb.putItem(ddbParams).promise()
console.log("Success");
} catch (err) {
console.log("Error", err);
}
console.log("Success: Everything executed correctly");
context.done(null, event);
} else {
// Nothing to do, the user's email ID is unknown
console.log("Error: Nothing was written to DDB or SQS");
context.done(null, event);
}
};
4. Post confirm Lambda
ユーザプール属性からPost confirm Lambdaトリガを追加します.
5. Test
Sign up
実装されたreactアプリケーションに会員を加入する.
ユーザプールには当然ユーザが生成されており,データベースを見るとユーザ情報がよく保存されていることがわかる.
リファレンス
https://docs.amplify.aws/guides/functions/cognito-trigger-lambda-dynamodb/q/platform/js/#create-the-lambda-function
https://velog.io/@seunghwa 17/Cognito-Pool-information-DynamoDB-保存
Reference
この問題について(AWS識別ユーザプールをDynamoDBに保存する), 我々は、より多くの情報をここで見つけました
https://velog.io/@dlruddms5619/AWS-Cognito-User-pool을-DynamoDB에-저장하기
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
User Poolは既に作成されており、属性は以下の通りです.
ユーザID、Email、name、subからなる.
2. Create DynamoDB Table
ユーザーIDをパーティションキーとして使用するテーブルを作成します.
すべての設定はデフォルトで使用され、パーティションキーはIDに設定され、タイプはStringに設定され、生成されます.
3. Create Lambda
データベース内のLambdaを作成します.LambdaコンソールにAddUserFuncというRamdaを作成し、次のコードを記述しました.
index.jsvar aws = require('aws-sdk');
var ddb = new aws.DynamoDB({apiVersion: '2012-10-08'});
exports.handler = async (event, context) => {
console.log(event);
let date = new Date();
// If the required parameters are present, proceed
if (event.request.userAttributes.sub) {
// -- Write data to DDB
let ddbParams = {
Item: {
'id': {"S": event.request.userAttributes.sub},
'__typename': {"S": 'User'},
'username': {"S": event.userName},
'name': {"S": event.request.userAttributes.name},
'email': {"S": event.request.userAttributes.email}
},
TableName: "sampleUserPoolTbl"
};
// Call DynamoDB
try {
await ddb.putItem(ddbParams).promise()
console.log("Success");
} catch (err) {
console.log("Error", err);
}
console.log("Success: Everything executed correctly");
context.done(null, event);
} else {
// Nothing to do, the user's email ID is unknown
console.log("Error: Nothing was written to DDB or SQS");
context.done(null, event);
}
};
4. Post confirm Lambda
ユーザプール属性からPost confirm Lambdaトリガを追加します.
5. Test
Sign up
実装されたreactアプリケーションに会員を加入する.
ユーザプールには当然ユーザが生成されており,データベースを見るとユーザ情報がよく保存されていることがわかる.
リファレンス
https://docs.amplify.aws/guides/functions/cognito-trigger-lambda-dynamodb/q/platform/js/#create-the-lambda-function
https://velog.io/@seunghwa 17/Cognito-Pool-information-DynamoDB-保存
Reference
この問題について(AWS識別ユーザプールをDynamoDBに保存する), 我々は、より多くの情報をここで見つけました
https://velog.io/@dlruddms5619/AWS-Cognito-User-pool을-DynamoDB에-저장하기
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
データベース内のLambdaを作成します.LambdaコンソールにAddUserFuncというRamdaを作成し、次のコードを記述しました.
index.js
var aws = require('aws-sdk');
var ddb = new aws.DynamoDB({apiVersion: '2012-10-08'});
exports.handler = async (event, context) => {
console.log(event);
let date = new Date();
// If the required parameters are present, proceed
if (event.request.userAttributes.sub) {
// -- Write data to DDB
let ddbParams = {
Item: {
'id': {"S": event.request.userAttributes.sub},
'__typename': {"S": 'User'},
'username': {"S": event.userName},
'name': {"S": event.request.userAttributes.name},
'email': {"S": event.request.userAttributes.email}
},
TableName: "sampleUserPoolTbl"
};
// Call DynamoDB
try {
await ddb.putItem(ddbParams).promise()
console.log("Success");
} catch (err) {
console.log("Error", err);
}
console.log("Success: Everything executed correctly");
context.done(null, event);
} else {
// Nothing to do, the user's email ID is unknown
console.log("Error: Nothing was written to DDB or SQS");
context.done(null, event);
}
};
4. Post confirm Lambda
ユーザプール属性からPost confirm Lambdaトリガを追加します.
5. Test
Sign up
実装されたreactアプリケーションに会員を加入する.
ユーザプールには当然ユーザが生成されており,データベースを見るとユーザ情報がよく保存されていることがわかる.
リファレンス
https://docs.amplify.aws/guides/functions/cognito-trigger-lambda-dynamodb/q/platform/js/#create-the-lambda-function
https://velog.io/@seunghwa 17/Cognito-Pool-information-DynamoDB-保存
Reference
この問題について(AWS識別ユーザプールをDynamoDBに保存する), 我々は、より多くの情報をここで見つけました
https://velog.io/@dlruddms5619/AWS-Cognito-User-pool을-DynamoDB에-저장하기
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
Sign up
実装されたreactアプリケーションに会員を加入する.
ユーザプールには当然ユーザが生成されており,データベースを見るとユーザ情報がよく保存されていることがわかる.
リファレンス
https://docs.amplify.aws/guides/functions/cognito-trigger-lambda-dynamodb/q/platform/js/#create-the-lambda-function
https://velog.io/@seunghwa 17/Cognito-Pool-information-DynamoDB-保存
Reference
この問題について(AWS識別ユーザプールをDynamoDBに保存する), 我々は、より多くの情報をここで見つけました https://velog.io/@dlruddms5619/AWS-Cognito-User-pool을-DynamoDB에-저장하기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol