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.

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
35
views
asked 5 days ago

State Machine times-out on Choice

I updated my state machine to use a task token and now it's timing out when it gets to the choice. This was previously working, and the cloudwatch logs for the first supportticketparse lambda function aren't indicating that anything is wrong. My guess is that I have and error in the payload definition, but I'm not sure. Is anything obviously wrong with the definition? If not, where else can I look for a potential problems? ``` { "Comment": "A description of my state machine", "StartAt": "zen sort", "TimeoutSeconds": 60, "States": { "zen sort": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke.waitForTaskToken", "OutputPath": "$.Payload", "Parameters": { "FunctionName": "arn:aws:lambda:us-east-1:363540650061:function:support-ticket-parse:$LATEST", "Payload": { "ExecutionContext.$": "$$", "APIGatewayEndpoint": "https://9084s1lza7.execute-api.us-east-1.amazonaws.com/test/", "Payload.$": "$" } }, "Next": "Choice" }, "Choice": { "Type": "Choice", "Choices": [ { "Variable": "$.name", "StringMatches": "New User Account ", "Next": "send email" }, { "Not": { "Variable": "$.name", "StringMatches": "New User Account " }, "Next": "Fail" } ], "Default": "Fail" }, "send email": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke.waitForTaskToken", "OutputPath": "$.Payload", "Parameters": { "FunctionName": "arn:aws:lambda:us-east-1:363540650061:function:send_email:$LATEST", "Payload": { "ExecutionContext.$": "$$", "APIGatewayEndpoint": "https://9084s1lza7.execute-api.us-east-1.amazonaws.com/test/", "Payload.$": "$" } }, "Retry": [ { "ErrorEquals": [ "Lambda.ServiceException", "Lambda.AWSLambdaException", "Lambda.SdkClientException" ], "IntervalSeconds": 2, "MaxAttempts": 6, "BackoffRate": 2 } ], "End": true }, "Fail": { "Type": "Fail" } } } ```
2
answers
0
votes
46
views
asked 6 days ago

API call from lambda function to AWS.SSM.putParameter() returns success, but leaves SSM.parameters unchanged

Hello all, AWS and node.js noob here. I am trying to save a code captured from URL parameters to my parameters store in the System Manager service, and later return a hashed value from various strings. My code returns the hash and I don't have any errors in the console, but when I test it with URL/?code=1234&challenge_code=5678, nothing changes in my parameter store. I already have an object named ebayUserCode in there of type string. ``` exports.handler = async (event) => { const crypto = require('crypto'); const AWS = require('aws-sdk') let verificationToken = "FIXME"; let endpoint = "FIXME"; let code = "code"; let challengeCode = "challenge_code"; if (event.queryStringParameters && event.queryStringParameters.code) { console.log("Received name: " + event.queryStringParameters.code); code = event.queryStringParameters.code; var ssm = new AWS.SSM(); var params = { Name: 'ebayUserCode', /* required */ Value: code, /* required */ Overwrite: true }; ssm.putParameter(params, function(err, data) { if (err) console.log(err, err.stack); // an error occurred else console.log(data); // successful response }); } if (event.queryStringParameters && event.queryStringParameters.challengeCode) { console.log("Received name: " + event.queryStringParameters.challengeCode); challengeCode = event.queryStringParameters.challengeCode; } const hash = crypto.createHash('sha256'); hash.update(challengeCode); hash.update(verificationToken); hash.update(endpoint); const responseHash = hash.digest('hex'); console.log(new Buffer.from(responseHash).toString()); const response = { statusCode: 200, body: responseHash, }; return response; }; ``` What am I doing wrong? Any help would be greatly appreciated. Thanks in advance!
2
answers
0
votes
41
views
asked 9 days ago
  • 1
  • 12 / page