AWMS support lambda server without server

I developed a website using node.js as source code. Recently, I am trying to make it serverless and deploy to lambda. I will rewrite most of my code, but just do not understand how to save the session after the user logs in. I used the express session module, and all session data is written to the database.

To be honest, I don’t have a deep understanding of the sessions. I searched on Google and did not find what I need. Does anyone have sample code to support sessions using lambda? or any resources. Many thanks!

+4
source share
2 answers

There are several mechanisms available in HTTP for conducting sessions in web applications, such as cookies (standard HTTP header), URL parameters, URL arguments in GET requests, body arguments in POST requests, such as hidden form fields (HTML forms) or custom HTTP request headers.

Source: Session Management Screenshot

AWS Lambda has nothing to do with session management unless you want to reinvent the wheel and write Lambda functions that store / retrieve session variables from the database, in which case I recommend that you use Amazon Cognito to manage the session. See the Amazon Cognito SDK for JavaScript .

+2
source

Amazon Cognito Identity SDK Javascript , , 16, , Cognito. .

    var poolData = {
        UserPoolId : '...', // Your user pool id here
        ClientId : '...' // Your client id here
    };
    var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
    var cognitoUser = userPool.getCurrentUser();

    if (cognitoUser != null) {
        cognitoUser.getSession(function(err, session) {
            if (err) {
                alert(err);
                return;
            }
            console.log('session validity: ' + session.isValid());
            // other AWS actions ...
        });
    }
+1

Source: https://habr.com/ru/post/1666864/


All Articles