0

尝试在 NodeJS 上使用 aws-sdk/cognito。尝试调用adminCreateUser,但一直遇到意外错误。下面的代码:

import corsHeaders from '../config/cors-headers'

import {
  CognitoIdentityProviderClient,
  AdminCreateUserCommand
} from '@aws-sdk/client-cognito-identity-provider'

const client = new CognitoIdentityProviderClient({
  region: 'us-east-1',
  credentials: {
    accessKeyId: '<key>',
    secretAccessKey: '<secretkey>',
  }
})

const adminCreateUser = async (request) => {
  const json = await request.json() // eslint-disable-line

  const params = {
    UserPoolId: '<poolid>',
    Username: '<email>',
    DesiredDeliveryMediums: [
      'EMAIL'
    ],
    ForceAliasCreation: false,
    MessageAction: 'SUPPRESS',
    UserAttributes: [
      {
        Name: 'email',
        Value: '<email>'
      }
      {
        Name: 'name',
        Value: 'Saul Goodman'
      },
      {
        Name: 'phone_number',
        Value: '+16472221111'
      }
    ]
  }

  const command = new AdminCreateUserCommand(params)

  console.log('trying to create user')

  let data = 123

  try {
    data = await client.send(command)
    console.log(data)
  } catch (error) {
    console.log(error, JSON.stringify(error))
    data = error
  }

  return new Response(JSON.stringify(data), {
    headers: {
      'Content-Type': 'application/json',
      ...corsHeaders
    }
  })

}

export default adminCreateUser

错误是:

{
  "__type": "InvalidSignatureException",
  "name": "InvalidSignatureException",
  "$fault": "client",
  "$metadata": {
    "httpStatusCode": 400,
    "requestId": "1269dcb8-73a2-431a-81b4-eb44193285c8",
    "attempts": 3,
    "totalRetryDelay": 123
  }
}

知道这个错误消息是什么意思吗?

4

0 回答 0