Giter VIP home page Giter VIP logo

aliyun-sdk-js's Introduction

原来 阿里云 js sdk 还能这么用

Open5 - 基于阿里云 Open API 的开源 H5 生成工具 https://github.com/aliyun-UED/open5

在浏览器端使用

现在 aliyun sdk 支持在浏览器端调用, 只需要引入 dist/aliyun-sdk.js 即可, 使用参考 sample/browser/browser.html

目前支持在浏览器端调用除了 sls, ocs 以外的所有服务, 不过目前只有 oss 支持 sts 和 cors , 非 oss 服务只能使用根 accessKey 和 accessSecret 进行初始化, 存在泄露风险.

如何 build

考虑到文件大小, 目前 dist/aliyun-sdk.js 中仅包含 oss 服务, 如果需要 build 其他服务, 请按照以下步骤操作:

  • git clone [email protected]:aliyun-UED/aliyun-sdk-js.git
  • cd aliyun-sdk-js
  • npm install
  • bower install
  • npm install -g browserify
  • 构建仅包含 oss 的 aliyun-sdk.js
browserify -r oss-2013-10-15.json browser.js > dist/aliyun-sdk.js
  • 如果需要编译多个服务, 如 oss, batchCompute
browserify -r oss-2013-10-15.json -r batchcompute-2015-06-30.json browser.js > dist/aliyun-sdk.js

目前在浏览器端运行的 sdk 还在测试阶段, 如果有问题请随时提出.

初始化

var oss = new ALY.OSS({
  accessKeyId: "在阿里云OSS申请的 accessKeyId",
  secretAccessKey: "在阿里云OSS申请的 secretAccessKey",
  securityToken: "",
  endpoint: 'http://oss-cn-hangzhou.aliyuncs.com',
  apiVersion: '2013-10-15'
});

可以使用 STS token 初始化 OSS, 后续 sts 会支持其他服务

var oss = new ALY.OSS({
  accessKeyId: "sts token 中的 accessKeyId",
  secretAccessKey: "sts token 中的 secretAccessKey",
  securityToken: "sts token 中的 securityToken",
  endpoint: 'http://oss-cn-hangzhou.aliyuncs.com',
  apiVersion: '2013-10-15'
});

安装

Node.js 安装

npm install aliyun-sdk

使用方法及代码示例

OSS

在 samples/oss 目录下的代码示例,使用方法:

  • 将 sample/oss/oss.js 中需要的参数修改
  • 打开需要执行的某个实例文件,如 GetBucket.js,将其中的参数改成你自己的 oss 实例参数
  • 执行示例文件即可, 如:
cd samples/oss
node GetBucket.js

oss 支持 stream 请使用 https://github.com/berwin/aliyun-oss-upload-stream

SLS

在 samples/sls 目录下的代码示例,使用方法:

  • 将 samples/sls/sls.js 中需要的参数修改
  • 打开需要执行的某个实例文件,如 ListLogStores.js,将其中的参数改成你自己的 sls 实例参数
  • 执行示例文件即可, 如:
cd samples/sls
node ListLogStores.js

ECS, RDS, SLB, CDN

在 samples 对应目录下的有代码示例,使用方法:

  • 将 samples/ecs/test.js 中需要的参数修改
  • 执行示例文件即可, 如:
cd samples/ecs
node test.js

OpenSearch

在 samples/opensearch 目录下的代码示例,使用方法:

  • 修改 samples/opensearch/opensearch.js,填入代码中所需参数
  • 执行示例文件即可

MEMCACHED

在 samples/memcached 目录下的代码示例,使用方法:

  • 修改 samples/memcached/memcached.js,填入代码中所需参数
  • 执行示例文件即可

更多帮助参考 https://github.com/chylvina/node_memcached

目前支持的服务

SDK 目前支持下列服务:

服务名 类名 API 版本 API 文档
Aliyun ECS ALY.ECS 2014-05-26 ECS API手册
Aliyun RDS ALY.RDS 2014-08-15 RDS API手册
Aliyun SLB ALY.SLB 2014-05-15 SLB API手册
Aliyun ESS ALY.SLB 2014-08-28 ESS API手册
Aliyun OSS ALY.OSS 2013-10-15 OSS API手册
Aliyun OTS ALY.OTS 2014-08-08 OTS API手册
Aliyun CDN ALY.CDN 2014-11-11 CDN API手册
Aliyun CMS ALY.CMS 2015-10-20 CMS API手册
Aliyun SLS ALY.SLS 2014-11-18 SLS API手册
Aliyun RAM ALY.RAM 2015-05-15 RAM API手册
Aliyun STS ALY.STS 2015-04-01 STS API手册
Aliyun MTS ALY.MTS 2014-06-18 MTS API手册
Aliyun PUSH ALY.PUSH 2015-08-27 PUSH API手册
Alidayu ALY.DAYU 2015-12-16 阿里大于 API手册
Alyun GREEN ALY.GREEN 2016-11-24 阿里绿网 API手册
Aliyun OpenSearch ALY.OpenSearch 2015-01-01 OpenSearch API手册
Aliyun BatchCompute ALY.BatchCompute 2015-06-30 BatchCompute API手册
Aliyun OCS memcached ALY.MEMCACHED BinaryProtocolRevamped
Aliyun JAQ ALY.JAQ 数控风险

我们在代码中参考了 AWS SDK,在此声明。

License

This SDK is distributed under the Apache License, Version 2.0.

aliyun-sdk-js's People

Contributors

xiong-liang avatar chylvina avatar aleelock avatar goto100 avatar mayunlei avatar jacksontian avatar hegar avatar jsl9208 avatar jasongao180 avatar eldereal avatar ruder avatar bodyno avatar

Watchers

James Cloos avatar chengfei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.