By using AWS re:Post, you agree to the Terms of Use

Questions tagged with Serverless

Sort by most recent
  • 1
  • 12 / page

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Error when using converted CJS > ESM npm library

I am trying out using ESM for some Lambda NodeJS functions. I have a compiled js file (from typescript, using esnext), a symlink to the node_modules folder (see https://github.com/vibe/aws-esm-modules-layer-support) and a basic package.json file that has a name, and `"type": "module"` set. Some functions work fine, but a few that use a shared package are not loading. The package is this one, https://github.com/capaj/object-resolve-path, but I have forked it to my own private repo, and converted it to ESM. I don't get any TS compilation errors, but when I try to invoke the function, it is failing with the following error: > 2022-08-12T12:58:58.467Z undefined ERROR Uncaught Exception {"errorType":"Runtime.UserCodeSyntaxError","errorMessage":"SyntaxError: Unexpected token '{'","stack":["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '{'"," at _loadUserApp (file:///var/runtime/index.mjs:724:17)"," at async Object.module.exports.load (file:///var/runtime/index.mjs:741:21)"," at async file:///var/runtime/index.mjs:781:15"," at async file:///var/runtime/index.mjs:4:1"]} I'm not getting any syntax errors show when editing the module code in VSCode. So I must have converted the module wrong? But I can't see what is wrong. I added an index.d.ts file with: ``` declare module 'object-resolve-path' { export default function resolvePath(obj: any, path: string): any; } ``` And changed `module.exports` to `export const ...` eg Before ``` var Path = require('./path') module.exports = function (o, path) { if (typeof path !== 'string') { throw new TypeError('path must be a string') } if (typeof o !== 'object') { throw new TypeError('object must be passed') } var pathObj = Path.get(path) if (!pathObj.valid) { throw new Error('path is not a valid object path') } return pathObj.getValueFrom(o) } ``` Now ``` import Path from './path.js'; export default resolvePath(o, path) { if (typeof path !== 'string') { throw new TypeError('path must be a string') } if (typeof o !== 'object') { throw new TypeError('object must be passed') } var pathObj = Path.get(path) if (!pathObj.valid) { throw new Error('path is not a valid object path') } return pathObj.getValueFrom(o) } ``` I can't figure out anyway to debug this locally, as the lambda functions are part of a mono-repo setup, and they deploy via cloudformation as various stacks.
0
answers
0
votes
4
views
asked 3 days ago

Can't access userAttributes of listUsersRes.Users in AWS lambda function

I'm filtering out unconfirmed emails in lambda function. I jsut want to access email of every user in my listUsersRes.Users. I have tried for listUsersRes.Users[0].Username it is returning username perfectly. But when I'm trying listUsersRes.Users[0].Email or listUsersRes.Users[0].userAttributes.email or listUsersRes.Users[0].request.userAttributes.email it is returning null. I have aslo AttributesToGet: ["email"].But I don't know why it is not working for email. **My function:** ``` exports.handler = async (event, context, callback) => { const cognitoProvider = new aws.CognitoIdentityServiceProvider({apiVersion: "2016-04-18"}); if (event.triggerSource == "PreSignUp_SignUp" ||event.triggerSource == "PreSignUp_AdminCreateUser" || event.triggerSource=="PreSignUp_ExternalProvider") { try { const listUserParams={UserPoolId: event.userPoolId,AttributesToGet: ["email"],Filter: `cognito:user_status= \"${"UNCONFIRMED"}\"`, Limit: 10 }; const listUsersRes = await cognitoProvider.listUsers(listUserParams).promise(); if (listUsersRes.Users.length >= 0) { return callback(new Error(listUsersRes.Users[0].Username), event);//this line I'm modifying to get email attribute form listUsersRes.Users[0] } } catch (error) {return callback(new Error("catch error"), event);} } else { var error = "This provider is not supported"; callback(new Error(error), event); } }; ``` **my permission:** ``` "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "logs:CreateLogStream", "logs:PutLogEvents", "cognito-idp:AdminInitiateAuth", "cognito-idp:ListUsers", "cognito-idp:AdminUpdateUserAttributes", "cognito-idp:AdminGetUser" ], ```
0
answers
0
votes
39
views
asked 9 days ago
  • 1
  • 12 / page