$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>python 3.x - AWS Cognito Post authentication Lambda trigger - return NotAuthorizedException - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python 3.x - AWS Cognito Post authentication Lambda trigger - return NotAuthorizedException - Stack Overflow

matteradmin13PV0评论

I've implemented soft delete functionality with Cognito by marking a custom user status field as deleted. However, I need to catch login attempts and reject them in the Post authentication Lambda trigger as if they are unrecognized users. How do you do that in Python 3.9?

All I am getting is "Unrecognizable lambda output" and "InvalidLambdaResponseException" when I try to return an error.

I tried throwing an error or stuff along the lines of:

          return {
                    "body": json.dumps({}, default=str),
                    "statusCode": 400,
                    "headers": {
                        "Access-Control-Allow-Origin": "*",
                        "Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
                        # "Content-Length": "79",
                        "Content-Type": "application/x-amz-json-1.1",
                        # "Date": "Fri, 15 Nov 2024 19:14:19 GMT",
                        "X-Amzn-Errormessage": "Incorrect username or password.",
                        "X-Amzn-Errortype": "NotAuthorizedException:",
                        "X-Amzn-Requestid": context.aws_request_id
                    }
                }

I've implemented soft delete functionality with Cognito by marking a custom user status field as deleted. However, I need to catch login attempts and reject them in the Post authentication Lambda trigger as if they are unrecognized users. How do you do that in Python 3.9?

All I am getting is "Unrecognizable lambda output" and "InvalidLambdaResponseException" when I try to return an error.

I tried throwing an error or stuff along the lines of:

          return {
                    "body": json.dumps({}, default=str),
                    "statusCode": 400,
                    "headers": {
                        "Access-Control-Allow-Origin": "*",
                        "Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
                        # "Content-Length": "79",
                        "Content-Type": "application/x-amz-json-1.1",
                        # "Date": "Fri, 15 Nov 2024 19:14:19 GMT",
                        "X-Amzn-Errormessage": "Incorrect username or password.",
                        "X-Amzn-Errortype": "NotAuthorizedException:",
                        "X-Amzn-Requestid": context.aws_request_id
                    }
                }
Share Improve this question asked Nov 16, 2024 at 6:52 JustANoobJustANoob 871 gold badge2 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I think the feature you're actually looking for is enabling/disabling users. There's no need to build your own solution using Lambda triggers, this is available out of the box.

You can use the AdminDisableUser API to deactivate a specific user, which prevents them from logging in, which can effectively become a soft-delete. If you want, you can still add a custom attribute to make it more explicit.

If you want to undo the soft delete, you just use AdminEnableUser to reactivate them.

Since you're using Python, here are the corresponding boto3 docs:

  • admin_disable_user
  • admin_enable_user
Post a comment

comment list (0)

  1. No comments so far