用户注册时发送电子邮件 - AWS Cognito 联合身份

send email when user registers - AWS Cognito federated Identities

如何在新用户注册时发送 email/trigger lambda 函数?

在"edit identity pool"下我只找到了一个同步触发器。 如果我理解正确的话:每次用户同步他的数据时都会触发这个...
有什么方法可以仅针对 "initial" 同步或为用户创建特定数据集时触发 lambda 函数?

编辑:
更具体地说:我确实使用 JS SDK 通过 lambdas 创建了用户。我在自己的 oauth2 流程中使用开发人员身份验证。我不知道如何区分授予访问权限的用户,例如通过 Google 第一次来自第二次这样做的人。带有访问代码的 json 对我来说是一样的……也许我弄错了。

同样使用 getOpenIdTokenForDeveloperIdentity 调用,我不知道如何区分 Cognito 的新 ID 和 Cognito 已知的 ID。

编辑 2: 更准确地说: 我正在构建这个项目:https://github.com/laardee/serverless-authentication-boilerplate/blob/master/authentication/lib/storage/usersStorage.js

这是我目前如何将用户保存到认知状态。 我为第一次使用和第 n 次使用的用户执行 运行 这段代码。我的问题是不知道怎么区分...

const saveCognito = (profile) => new Promise((resolve, reject) => {
  if (profile) {
    cognitoidentity.getOpenIdTokenForDeveloperIdentity({
      IdentityPoolId: process.env.COGNITO_IDENTITY_POOL_ID,
      Logins: {
        // profile.userId = encrypted id of the e.g. google oauth2 id
        [process.env.COGNITO_PROVIDER_NAME]: profile.userId 
      }
    }, (err, dat) => {
      if (err) {
        reject(err);
      } else {
        var list_params = {
          DatasetName: 'user-data', /* dataset name */
          IdentityId: dat.IdentityId, /* cognito id */
          IdentityPoolId: process.env.COGNITO_IDENTITY_POOL_ID
        };
        cognitosync.listRecords(list_params, function(err, data) {
          if (err) {
            reject(err); // an error occurred
          } else {

            var RecordPatches = //[Parts of the i want to write to the user]
            // SyncSessionToken is returned by the cognitosync.listRecords call
            list_params["SyncSessionToken"] = data.SyncSessionToken; 
            list_params["RecordPatches"] = RecordPatches;

            cognitosync.updateRecords(list_params, function(err, update_data) {
              if (err){
                reject(err);
              } else {
                resolve();
              }
            });
          }
        });
      }
    });
  } else {
    reject('Invalid profile');
  }
});

所以这是 Cognito 目前不支持开箱即用的功能。您说得对,唯一会触发 Lambda 函数的内置 Cognito 事件是 "Sync Trigger" 事件。每次 Cognito IdentityId 将他们的一些数据同步到 Cognito Sync 云数据存储时,都会触发此 Sync 事件。

此事件与 Cognito Federated Identity 创建新的 IdentityId 无关。

理论上你可以:

  • 运行 在用户登录之前对 IdentityPool 进行列表身份调用 英寸
  • 登录用户。检查已提供给用户的 IdentityId 是否存在于您在登录之前检索到的列表中 in. 这会告诉你他们的身份是否是 给定在此登录之前存在。
  • 根据这些信息,您可以 决定是否以编程方式调用 Lambda 从您的应用程序运行。

上述设置会很复杂,因为出于安全原因,您需要在服务器端维护此服务。 list-identities 调用需要 AWS 凭证才能调用。我怀疑您是否希望在您的 IAM 策略中为未经身份验证的用户包含该调用的权限。

除上述内容外,目前您无能为力。 为此,您需要设置一个 DynamoDB table(或一些类似的低延迟数据存储),您可以在其中维护 IdentityId 列表的状态,然后在您登录时查询此 service/store用户将新登录与预先存在的列表进行比较。

如果这对您的用例至关重要,我建议您前往 AWS Support,并创建一个案例,您可以在其中将其记录为功能请求。

https://aws.amazon.com/premiumsupport/