百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

amazon-cognito-js

> 编程语言
开源

Amazon Cognito Sync Manager 为 JavaScript

199 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Amazon Cognito Sync Manager 为 JavaScript

Amazon Cognito Sync Manager for JavaScript

Developer Preview: We welcome developer feedback on this project. You can reach us by creating an issue on the GitHub repository or post to the Amazon Cognito forums:

  • https://github.com/aws/amazon-cognito-js/issues
  • https://forums.aws.amazon.com/forum.jspa?forumID=173

Introduction

The Cognito Sync Manager for JavaScript allows your web application to store data in the cloud for your users and synchronize across other devices. The library uses the browser's local storage API to create a local cache for the data, similar to our mobile SDK. This allows your web application to access stored data even when there is no connectivity.

Note: This library is designed to run in the browser. It has not been tested for use in other environments.

Setup

  1. Download and include the AWS JavaScript SDK:
  • http://aws.amazon.com/sdk-for-browser/
  1. Download and include the Cognito Sync Manager for JavaScript:
  • Or... import 'amazon-cognito-js';
  • Or... require('amazon-cognito-js');

For NPM usage refer to the following issue: NPM usage.

Usage

Step 1. Log into Amazon Cognito management console and create a new identity pool. Be sure to enable the "unauthenticated identities" option. On the last step of the wizard, make a note of your Account ID, Identity Pool ID, and Unauthenticated Role ARN.

  • https://console.aws.amazon.com/cognito/home/?region=us-east-1

Step 2. Instantiate the AWS JavaScript SDK using the AWS.CognitoIdentityCredentials class, using the information you gathered from the previous step.

javascript
AWS.config.region = 'us-east-1';

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'YOUR IDENTITY POOL ID',
});

Step 3. Make the call to obtain the credentials you configured, and in the callback, instantiate the CognitoSyncManager class. It will assume the credentials from the AWS SDK.

javascript
AWS.config.credentials.get(function() {

    client = new AWS.CognitoSyncManager();

    // YOUR CODE HERE

});

Step 4. Now you need to open or create a new dataset to start saving data to. Call .openOrCreateDataset() and pass in the desired dataset name.

javascript
client.openOrCreateDataset('myDatasetName', function(err, dataset) {

   // Do something with the dataset here.

});

Step 5. Once you have the dataset object, you can write, read, and delete records to that dataset. It is also possible to get all the records from a given dataset, get the amount of data used by a dataset, and more.

javascript

dataset.get('myRecord', function(err, value) {
  console.log('myRecord: ' + value);
});

dataset.put('newRecord', 'newValue', function(err, record) {
  console.log(record);
});

dataset.remove('oldKey', function(err, record) {
  if (!err) { console.log('success'); }
});

Step 6. Finally, synchronize the data to Cognito. You pass the synchronize function an object with callbacks to handle the various outcomes: onSuccess, onFailure, onConflict, onDatasetsMerged, onDatasetDeleted.

…

Change Log

v1.0.0:

  • Initial release. Developer preview.

Issues· 36 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言