javascript - Cognito 从 Pre Sign-up Lambda Trigger 发送什么样的事件
问题描述
我PreSignup
使用以下代码创建了一个 Lambda 函数以与 Cognito Pre-SignUp 触发器一起使用:
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
export async function PreSignup(event: any, context: APIGatewayEventDefaultAuthorizerContext,) {
console.log("...event:", event);
console.log("...context:", context);
let userName = event.userName;
let email = event.request.userAttributes.email;
console.log("...userName:", userName);
console.log("...email:", email);
// Confirming the event so Cogntio doesnt resend it again:
event.response.autoConfirmUser = true;
event.response.autoVerifyPhone = true;
event.response.autoVerifyEmail = true;
return event;
}
我宁愿指定事件的类型,而不是设置event
to 。any
function PreSignup(event: any)
我试图这样指定它APIGatewayProxyEvent
:
function PreSignup(event: APIGatewayProxyEvent, context: APIGatewayEventDefaultAuthorizerContext,) {...}
但它不起作用,因为event
Cognito Pre Sign-Up 触发器发送的不是一种APIGatewayProxyEvent
类型。这是什么活动?
后来编辑:
以下是 Cognito PreSignUp Trigger 推送的复制/粘贴事件:
{
version: '1',
region: 'us-east-1',
userPoolId: 'us-east-1_abcdef',
userName: 'emailf@address.com',
callerContext: {
awsSdkVersion: 'aws-sdk-nodejs-2.799.0',
clientId: 'CLIENT_ID_NOT_APPLICABLE'
},
triggerSource: 'PreSignUp_AdminCreateUser',
request: {
userAttributes: { email: 'emailf@address.com' },
validationData: null
},
response: {
autoConfirmUser: false,
autoVerifyEmail: false,
autoVerifyPhone: false
}
}
下面是这次推送的另一个 AWS 事件的示例AWS EventBridge
(类似于 Cognito Trigger 推送的事件):
{
version: '0',
id: '0ee136cb-ea53-f9e0-a6a9-232dfb78b7d0',
'detail-type': 'UserCreated',
source: 'my.company.endpointname',
account: '123456789012',
time: '2021-01-29T03:05:54Z',
region: 'us-east-1',
resources: [],
detail: { foo: 'bar', createdAt: 1611889553709 }
}
解决方案
PreSignUp_SignUp
:您的标准 Cognito 池(用户名/密码)注册
PreSignUp_AdminCreateUser
:当使用 admin 方法创建用户时(要清楚,不是在您创建管理员时,而是当您是管理员时创建不同的用户)。
PreSignUp_ExternalProvider
:如果您有第三方注册,例如 Google 或 facebook
{
"version":"1",
"region":"us-east-1",
"userPoolId":"us-east-1_xxxxxxx",
"userName":"2d4eb80f-7998-xxxx-xxxx-xxxxxxxxxx",
"callerContext":{
"awsSdkVersion":"aws-sdk-unknown-unknown",
"clientId":"xxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"triggerSource":"PreSignUp_SignUp",
"request":{
"userAttributes":{
"email":"xxxxxxxxxxxxxxx@gmail.com"
},
"validationData":null
},
"response":{
"autoConfirmUser":false,
"autoVerifyEmail":false,
"autoVerifyPhone":false
}
}
{
"version":"1",
"region":"us-east-1",
"userPoolId":"us-east-1_xxxxxxxxxxx",
"userName":"efce8c11-e0ff-4400-xxxx-xxxxxxxxxx",
"callerContext":{
"awsSdkVersion":"aws-sdk-java-1.11.856",
"clientId":"CLIENT_ID_NOT_APPLICABLE"
},
"triggerSource":"PreSignUp_AdminCreateUser",
"request":{
"userAttributes":{
"email_verified":"true",
"email":"xxxxxx@xxxxxxx.com"
},
"validationData":null
},
"response":{
"autoConfirmUser":false,
"autoVerifyEmail":false,
"autoVerifyPhone":false
}
}
{
"version":"1",
"region":"us-east-1",
"userPoolId":"us-east-1_xxxxxx",
"userName":"Google_xxxxxxxxxxxxxxxxxxxxx",
"callerContext":{
"awsSdkVersion":"aws-sdk-unknown-unknown",
"clientId":"xxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"triggerSource":"PreSignUp_ExternalProvider",
"request":{
"userAttributes":{
"email_verified":"false",
"cognito:email_alias":"",
"cognito:phone_number_alias":"",
"email":"xxxxxx@xxxxxx.com"
},
"validationData":{
}
},
"response":{
"autoConfirmUser":false,
"autoVerifyEmail":false,
"autoVerifyPhone":false
}
}
推荐阅读
- javascript - 使用流导出类的正确方法?
- html - 用 CSS 提取照片
- mongodb - 存储/过滤超过 100 万条记录的动态表的最佳方式
- java - 跨类/包维护全局但可变的变量
- excel - excel计算特定时期每月的天数
- amazon-web-services - 管理员可以访问 AWS 控制台,但不能通过 CLI 访问
- r - 在所有其他列上使用条件进行变异以添加新列
- xml - XML 模式中的 derivedBy 属性创建基本类型列表
- c# - RestRequest 在本地工作,但不是来自天蓝色“请求被中止:无法创建 SSL/TLS 安全通道。”
- flutter - 无法将JPG图像转换为PNG格式