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
已提问 1 年前376 查看次数
1 回答
0

Test with these sample values, it should work -

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

AWS
已回答 1 年前
  • 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" }

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则