serverless-aliyun-function-compute-wnj v1.1.27
Aliyun Function Compute Serverless Plugin
This plugin enables Aliyun Function Compute support within the Serverless Framework.
Getting started
Pre-requisites
- Node.js v8.x for using the plugin.
- Note that at the moment, Aliyun Function Compute only supports Node.js v4.4 and v6.x. v8.x support will be added to Function Compute later, but for now we still need to use a higher version of runtime to use the CLI.
- Serverless CLI v1.20.0+. You can get it by running
npm i -g serverless. - An Aliyun account.
Example
You can install the following example via:
serverless install --url https://github.com/aliyun/serverless-function-compute-examples/tree/master/aliyun-nodejsThe structure of the project should look something like this:
├── index.js
├── node_modules
├── package.json
└── serverless.ymlserverless.yml:
service: serverless-aliyun-hello-world
provider:
name: aliyun
runtime: nodejs6
credentials: ~/.aliyuncli/credentials # path must be absolute
plugins:
- serverless-aliyun-function-compute
package:
exclude:
- package-lock.json
- .gitignore
- .git/**
functions:
hello:
handler: index.hello
events:
- http:
path: /foo
method: getpackage.json:
{
"name": "serverless-aliyun-hello-world",
"version": "0.1.0",
"description": "Hello World example for aliyun provider with Serverless Framework.",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"serverless-aliyun-function-compute": "^1.0.0"
}
}index.js:
'use strict';
exports.hello = (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify({ message: 'Hello!' }),
};
callback(null, response);
};Note that ~/.aliyuncli/credentials is where the aliyun-cli puts the crendentials after running aliyuncli configure. You don't have to use aliyuncli though, you can just create a similar file with your own access keys and make sure pointing the value of the credentials field in serverless.yml to it.
In addition to aliyun_access_key_secret and aliyun_access_key_id, please configure aliyun_account_id (a numeric number for identifying your account, available in Aliyun Console) as well. This credential file should look something like this:
[default]
aliyun_access_key_secret = 098f6bcd4621d373cade4e832627b4f6
aliyun_access_key_id = nA5hjMhbg9BOoVo
aliyun_account_id = 1504163990726See test/project for a more detailed example (including how to access other Aliyun services, how to set up a HTTP POST endpoint, how to set up OSS triggers, etc.).
Workflow
Deploy your service to Aliyun:
serverless deployIf your service contains HTTP endpoints, you will see the URLs for invoking your functions after a successful deployment.
Note: you can use
serverless deploy function --function <function name>to deploy a single function instead of the entire service.Invoke a function directly (without going through the API gateway):
serverless invoke --function helloRetrieve the LogHub logs generated by your function:
serverless logs --function helloGet information on your deployed functions
serverless infoWhen you no longer needs your service, you can remove the service, functions, along with deployed endpoints and triggers using:
serverless removeNote: by default RAM roles and policies created during the deployment are not removed. You can use
serverless remove --remove-rolesif you do want to remove them.
Develop
# clone this repo
git clone git@github.com:aliyun/serverless-aliyun-function-compute.git
# link this module to global node_modules
cd serverless-aliyun-function-compute
npm install
npm link
# try it out by packaging the test project
cd test/project
npm install
npm link serverless-aliyun-function-compute
serverless packageLicense
MIT
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago