Aws lambda 在认证后lambda触发器中获取AWS cognito认证用户

Aws lambda 在认证后lambda触发器中获取AWS cognito认证用户,aws-lambda,amazon-cognito,aws-amplify,aws-amplify-sdk-js,Aws Lambda,Amazon Cognito,Aws Amplify,Aws Amplify Sdk Js,我正在使用Amplify和Cognito后端来验证我的用户,基本上是作为LDAP impl。这是所有配置和工作刚刚好。在用户池中设置用户,并正确验证。(注意:我使用的是默认的放大控件,所以它可以正常工作) 但是,现在我希望能够提取经过身份验证的用户及其所有数据(包括用户属性),以便更新用户。作为第一步,我将尝试将经过身份验证的用户登录到控制台。最后,我将使用这个钩子来更新用户属性,方法是从数据库中提取一些数据进行更新 这是我试图使用的代码片段 exports.handler = async (e

我正在使用Amplify和Cognito后端来验证我的用户,基本上是作为LDAP impl。这是所有配置和工作刚刚好。在用户池中设置用户,并正确验证。(注意:我使用的是默认的放大控件,所以它可以正常工作)

但是,现在我希望能够提取经过身份验证的用户及其所有数据(包括用户属性),以便更新用户。作为第一步,我将尝试将经过身份验证的用户登录到控制台。最后,我将使用这个钩子来更新用户属性,方法是从数据库中提取一些数据进行更新

这是我试图使用的代码片段

exports.handler = async (event, context, callback) => {

    const Amplify = require('@aws-amplify/core')
    const Auth = require('@aws-amplify/auth')

    console.log("Amplify object: %o", Amplify)
    console.log("Auth object: %o", Auth)

    Amplify.configure({
        Auth: {
                identityPoolId: 'XXXX',
                region: event.region,
                userPoolId: event.userPoolId
        }
    });
    
    console.log("about to get current user");
    Auth.currentAuthenticatedUser().then(user => console.log(user));
    console.log("got current user and logged");
}
下面是输出的几个片段

INFO    Amplify object: {
  [__esModule]: true,
  Amplify: [Function: Amplify] {
    [length]: 0,
    [name]: 'Amplify',
    [prototype]: Amplify { [constructor]: [Circular] },
    register: [Function] {
      [length]: 1,
      [name]: '',
      [prototype]: { [constructor]: [Circular] }
    },
    configure: [Function] {
      [length]: 1,
      [name]: '',
      [prototype]: { [constructor]: [Circular] }
    },
    addPluggable: [Function] {
      [length]: 1,
      [name]: '',
      [prototype]: { [constructor]: [Circular] }
    },
    _components: [

我收到的错误是:

ERROR   Invoke Error    
{
    "errorType": "TypeError",
    "errorMessage": "Amplify.configure is not a function",
    "stack": [
        "TypeError: Amplify.configure is not a function",
        "    at Runtime.exports.handler (/var/task/index.js:171:13)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}

根据Amplify不能在Node中使用,因为它是前端库。

根据Amplify不能在Node中使用,因为它是前端库。

这个问题的答案是我需要在我的package.json中使用aws库。我已经把它包括进去了,但是没有。啊

这个问题的答案是我需要在package.json中使用aws库。我已经把它包括进去了,但是没有。啊

ERROR   Invoke Error    
{
    "errorType": "TypeError",
    "errorMessage": "Amplify.configure is not a function",
    "stack": [
        "TypeError: Amplify.configure is not a function",
        "    at Runtime.exports.handler (/var/task/index.js:171:13)",
        "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
    ]
}