amazon-archives / amazon-cognito-js

Amazon Cognito Sync Manager for JavaScript
http://aws.amazon.com/cognito
Apache License 2.0
202 stars 83 forks source link

Using amazon-cognito-js in Lambda Function #55

Closed Leon-Africa closed 6 years ago

Leon-Africa commented 6 years ago

I uploaded zip file containing the module in Lambda function.

After doing AWS Cognito Logins map I get AWS Keys from sts, that works fine.

The issue is when I instantiate the Cognito Sync manager with:

var client = new AWS.CognitoSyncManager();

I get the following error:

screen shot 2017-09-07 at 11 30 05 am

It seems that this package will only work in browser? How can I use this package in Lambda Function?

Leon-Africa commented 6 years ago

I un-minified the js file and uploaded the file getting the following:

screen shot 2017-09-07 at 11 46 58 am

At line 607 code is:

AWS = AWS || {}, AWS.CognitoSyncManager = AWS.CognitoSyncManager || {}, AWS.CognitoSyncManager.StoreLocalStorage = function() { var a = function() { this.store = window.localStorage };

This is where Lambda is throwing the error "window is not defined".

The issue is how can we write a Sync data set from a Lambda function?

The nodejs api does not have such a method, but this package has:

client.openOrCreateDataset('testdataset', function(err, dataset) {

This works fine in browser but how can this be done in Lambda?

this.store = window.localStorage does not exist in Lambda function

wangxpert commented 6 years ago

I am also faced with this error.

itrestian commented 6 years ago

There's a note on the repo "This library is designed to run in the browser. It has not been tested for use in other environments."

Window and local storage which are used for storing data are only available in a browser environment.