2

I'm working on creating and lambda function using javascript to authenticate users using the AWS Cognito and Identity pools. But I need to include below JS library references in my lambda function code

aws-cognito-sdk.js
amazon-cognito-identity.min.js
aws-sdk.min.js"
moment.js
sjcl.js
jsbn.js
jsbn2.js

Given below is the part of the code that I used in the handler of the lambda function. How can I include the references to above javascripts inside my lambda function code?

exports.handler = function(event, context, callback) 
{
    // Cognito Identity Pool Id
    AWS.config.region = 'us-east-1';
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'us-east-1:xxxxxxxxxx',
    });

    // Cognito User Pool Id
    AWSCognito.config.region = 'us-east-1';
    AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
            IdentityPoolId: 'us-east-1:xxxxxxxx'
    });

    //...rest of the logic..
}

1 Answer 1

2

Well, you could make those libraries into Node packages if they aren't already, and then use "require" to include them. The drawback is that you'll have to upload them as a zipped folder from then on, rather than work in their web editor.

Sign up to request clarification or add additional context in comments.

6 Comments

@master565- Even as of now I'm creating a zip folder manually, including all the required files and uploading it to the lambda, therefore it wont be a issue at all. Could you please let me know how to create these node packages? or point me to anywhere there is an example.
Some of them already are (see github.com/andyperlitch/jsbn). This answer looks like a good workaround for converting any javascript file into a usable node file as well stackoverflow.com/questions/5171213/…
Thanks a lot, I'm working on this. I'll update you on the progress.
Sure thing. Let me know if you have any more questions, I'll try my best to answer them.
Just as an update, the web editor now allows you to edit files that are uploaded to a Lambda function as a ZIP package. At least you can edit the main handler file, I haven't had success with any other files.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.