Validation error in Lambda

0

Hi there,

in a step function tutorial by AWS (https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-get-started-parallel-tasks.html) I am asked to create a Lambda function in Node.js 16.x with this code:

const ssnRegex = /^\d{3}-?\d{2}-?\d{4}$/; const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;

class ValidationError extends Error { constructor(message) { super(message); this.name = "CustomValidationError"; } }

exports.handler = async (event) => { const { ssn, email } = event; console.log(SSN: ${ssn} and email: ${email});

const approved = ssnRegex.test(ssn) && emailRegex.test(email);

if (!approved) {
    throw new ValidationError("Check Identity Validation Failed");
}

return {
    statusCode: 200,
    body: JSON.stringify({
        approved,
        message: `Identity validation ${approved ? 'passed' : 'failed'}`
    })
}

};

The test returns an error though:

Response { "errorType": "CustomValidationError", "errorMessage": "Check Identity Validation Failed", "trace": [ "CustomValidationError: Check Identity Validation Failed", " at Runtime.exports.handler (/var/task/index.js:21:15)", " at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1085:29)" ] }

Can someone help me?

Moe
asked a year ago360 views
1 Answer
0

Test with these sample values, it should work -

ssn - 111-11-1111 email - fname.lname@domain.com

AWS
answered a year ago
  • thank you. I don't get where to put the sample values though, sorry. Are sample values necessary to test a lambda function?

  • Yes, they're required. When you test the Lambda function from AWS console, you'll have to pass a test event, the event should look like this -

    { ssn: "111-11-1111", email:"fname.lname@domain.com" }

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions