waliyun

3.2.2 • Public • Published

WAliyun

比官方SDK更好用的阿里云SDK。

npm npm npm

Minimum, Flexible, Scalable.

支持Lazy Require。

Table of Contents generated with DocToc

安装和使用

国际惯例:

npm install waliyun --save

公共参数:

var options = {
  AccessKeyId: 'xxxx-xxxx-xxxx-xxxx',
  AccessKeySecret: 'xxxx-xxxx-xxxx-xxxx',
  // 选填,不同接口类型注意版本日期,2.0.0之后版本会带上默认版本,但可能会落后于最新,需要注意
  Version: '2014-05-26',
  // 选填
  SignatureMethod: 'HMAC-SHA1',
  Format: 'json',
  SignatureVersion: '1.0',
  // 不填,每次请求都会自动重新生成
  SignatureNonce: Math.random(),
  Timestamp: new Date().toISOString()
};

ES5:

var WALIYUN = require('waliyun');
var ecs = WALIYUN.ECS(options);
ecs.describeInstances({
  RegionId: 'cn-hangzhou'
}).then(function(instances){
  // xxxx
});

ES7:

import {ECS} from 'waliyun';
const ecs = ECS(options);
// Within Async Func
(async() => {
  const instances = await ecs.describeInstances({
    RegionId: 'cn-hangzhou'
  });
  // xxxx
});

查看接口对应版本

ES7:

import {ECS} from 'waliyun';
const ecs = ECS(options);
console.log(ecs.version());

已支持的接口

CDN

API文档参考: https://help.aliyun.com/document_detail/27155.html

移动推送 CLOUDPUSH

API文档参考: https://help.aliyun.com/document_detail/30074.html

邮件推送 DM

API文档参考: https://help.aliyun.com/document_detail/29435.html

发送示例:

const { DM } = require('waliyun');
 
const dm = DM({
  AccessKeyId: 'xxxx',
  AccessKeySecret: 'xxxxx'
});
 
dm.singleSendMail({
  AccountName: 'no-reply@xxx.com',
  ReplyToAddress: false,
  AddressType: 1,
  ToAddress: 'xxx@qq.com',
  FromAlias: '用户名',
  Subject: '注册邮件',
  HtmlBody: '<p>您的注册验证码为:1234</p>'
}).then(data => {
  console.log(data);
}).catch(err => {
  console.log(err);
});
 

短信服务 SMS

阿里云已停止开通原短信服务(整合在消息服务内)。新开通阿里云短信服务的用户,请参考下方的新短信服务调用示例

发送示例:

const { SMS } = require('waliyun');
 
const sms = SMS({
  AccessKeyId: 'xxxx',
  AccessKeySecret: 'xxxx'
});
 
sms.singleSendSMS({
  ParamString: '{"customer":"1234"}',
  RecNum: '13812341234',
  SignName: '您的签名',
  TemplateCode: 'SMS_77778888'
}).then(data => {
  console.log(data);
});

新短信服务 DYSMS

API文档参考: https://help.aliyun.com/document_detail/56189.html

发送示例:

const { DYSMS } = require('waliyun');
 
const sms = DYSMS({
  AccessKeyId: 'xxxx',
  AccessKeySecret: 'xxxx'
});
 
sms.sendSms({
  TemplateParam: JSON.stringify({customer: '1234'}),
  PhoneNumbers: mobileNo,
  SignName: '您的签名',
  TemplateCode: 'SMS_77778888'
})

分布式关系型数据库 DRDS

API文档参考: https://help.aliyun.com/document_detail/35276.html

云服务器 ECS

API文档参考: https://help.aliyun.com/document_detail/25485.html

ES7 示例:

import {ECS} from 'waliyun';
 
(async() => {
  const ces = ECS({
    AccessKeyId: 'xxxx',
    AccessKeySecret: 'xxxx',
    Version: '2014-05-26'
  });
  const data = await ces.describeInstances({
    RegionId: 'cn-hangzhou'
  });
  console.log(data.Instances.Instance);
})();

语音服务 DYVMS

API文档参考: https://help.aliyun.com/document_detail/56190.html

弹性伸缩 ESS

API文档参考: https://help.aliyun.com/document_detail/25925.html

ALIDNS

API文档参考: https://help.aliyun.com/document_detail/29739.html

HTTPDNS

API文档参考: https://help.aliyun.com/document_detail/30122.html

阿里云物联网套件 IOT

API文档参考: https://help.aliyun.com/document_detail/30557.html

ES7 示例:

import {IOT} from 'waliyun';
 
(async() => {
  const iot = IOT({
    Api:'https://iot.cn-shanghai.aliyuncs.com/',//可不填,默认为https://iot.aliyuncs.com/
    AccessKeyId: 'xxxx',
    AccessKeySecret: 'xxxxx',
    Version: '2016-05-30'
  });
  const data = await iot.sub({
    ProductKey: 'xxxx',
    SubCallback: 'http://xxxx:xxx/',
    'Topic.1': '/ProductKey/Topic'
  });
  console.log(data);
})();

云监控 METRICS

API文档参考: https://help.aliyun.com/document_detail/28616.html

ES7 示例:

import {METRICS} from 'waliyun';
 
(async() => {
  const metrics = METRICS({
    AccessKeyId: 'xxxxxx',
    AccessKeySecret: 'xxxxxx',
    Version: '2015-10-20',
    RegionId: 'cn-hangzhou'
  });
  const data = await metrics.queryMetric({
    Project: 'acs_rds',
    Metric: 'CpuUsage',
    Period: '300',
    StartTime: new Date() - 60 * 1000 * 1000,
    Dimensions: '{instanceId:\'xxxxxx\'}'
  });
  console.log(data.Datapoints);
})();

媒体转码 MTS

API文档参考: https://help.aliyun.com/document_detail/29212.html

访问控制 RAM

API文档参考: https://help.aliyun.com/document_detail/28672.html

云数据库 RDS

API文档参考: https://help.aliyun.com/document_detail/26226.html

负载均衡 SLB

API文档参考: https://help.aliyun.com/document_detail/27566.html

访问控制 STS

API文档参考: https://help.aliyun.com/document_detail/28756.html

ES5示例:

var WALIYUN = require('waliyun');
var sts = WALIYUN.STS({
  AccessKeyId: 'xxxx',
  AccessKeySecret: 'xxxx',
  Version: '2015-04-01'
});
sts.AssumeRole({
  RoleArn: 'acs:ram::xxxx:role/xxxx',
  RoleSessionName: 'xxxxx'
},'post').then(function(token){
  // xxxx
});

ES7 示例:

import {STS} from 'waliyun';
 
const sts = STS({
  AccessKeyId: 'xxxx',
  AccessKeySecret: 'xxxx',
  Version: '2015-04-01'
});
 
(async() => {
  const token = await sts.AssumeRole({
    RoleArn: 'acs:ram::xxxx:role/xxxx',
    RoleSessionName: 'xxxxx'
  },'post');
  // xxxx
})();
 

容器服务 CS

API文档参考: https://help.aliyun.com/document_detail/26043.html

注意,容器服务版本号停留在:2015-12-15。新版改动较为奇葩,暂不支持。

旧版本方法列表:

[
  'GetClusterList',
  'CreateCluster',
  'DeleteCluster',
  'GetClusterById',
  'GetClusterCerts',
  'UpdateClusterSizeById',
  'ListProjects',
  'CreateProject',
  'RetrieveProject',
  'StartProject',
  'StopProject',
  'UpdateProject',
  'DeleteProject'
]

CHANGELOG

v2.0.0

2016-09-06

  • 使用元编程方式进行重构,减少重复代码和Action限制;
  • 更新文档链接。

v1.0.0

2016-05-16 解决了签名偶发错误的问题。

License

MIT

通过支付宝捐赠:

qr

Dependencies (2)

Dev Dependencies (3)

Package Sidebar

Install

npm i waliyun

Weekly Downloads

99

Version

3.2.2

License

MIT

Unpacked Size

15.5 kB

Total Files

25

Last publish

Collaborators

  • willin