【问题标题】:Getting AWS cognito authenticated user in post-authentication lambda trigger在身份验证后 lambda 触发器中获取 AWS cognito 身份验证用户
【发布时间】:2020-11-04 12:12:29
【问题描述】:

我使用 Amplify 和 Cognito 后端来验证我的用户,本质上是作为 LDAP 实现。这一切都已配置并且工作正常。用户在用户池中设置,并正确验证。 (注意:我使用的是默认的 Amplify 控件,因此可以按预期工作)。

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

这是我正在尝试使用的代码 sn-p

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");
}

这里有几个输出的 sn-ps ...

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: [

INFO    Auth object: {
  [__esModule]: true,
  Auth: AuthClass {
    userPool: null,
    user: null,
    oAuthFlowInProgress: false,
    currentUserCredentials: [Function: bound ] { [length]: 0, [name]: 'bound ' },

我收到的错误是:

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)"
    ]
}

【问题讨论】:

    标签: aws-lambda amazon-cognito aws-amplify aws-amplify-sdk-js


    【解决方案1】:

    根据this issue on github Amplify 不能在 Node 中使用,因为它是一个前端库。

    【讨论】:

      【解决方案2】:

      这个答案是我需要在我的 package.json 中使用 aws lib。我已经包含它,但它不可用。呵呵!

      【讨论】:

        猜你喜欢
        • 2018-03-04
        • 2022-06-20
        • 2016-12-22
        • 2017-01-02
        • 2018-01-29
        • 1970-01-01
        • 2016-06-25
        • 1970-01-01
        • 2022-06-19
        相关资源
        最近更新 更多