npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xanthous/serverless-aliyun-function-compute

v1.3.1

Published

Provider plugin for the Serverless Framework v1.x which adds support for Aliyun Function Compute

Downloads

4

Readme

Aliyun Function Compute Serverless Plugin

This plugin enables Aliyun Function Compute support within the Serverless Framework.

  • Build Status

Getting started

Pre-requisites

  • Node.js v8.x for using the plugin.
  • Serverless CLI v1.26.1+. You can get it by running npm i -g serverless.
  • An Aliyun account.

Example

You can install the following example from GitHub:

$ serverless install --url https://github.com/aliyun/serverless-function-compute-examples/tree/master/aliyun-nodejs

The structure of the project should look something like this:

├── index.js
├── node_modules
├── package.json
└── serverless.yml

Install serverless-aliyun-function-compute plugin to your service.

$ serverless plugin install --name serverless-aliyun-function-compute

serverless.yml:

service: serverless-aliyun-hello-world

provider:
  name: aliyun
  runtime: nodejs8
  credentials: ~/.aliyun_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: get

package.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"
}

index.js:

'use strict';

exports.hello = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({ message: 'Hello!' }),
  };

  callback(null, response);
};

In order to deploy this function, we need the credentials with permissions to access Aliyun Function Compute. Please create a credentials file and configure the credentials in it. Here is an example credentials file:

[default]
aliyun_access_key_id = xxxxxxxx
aliyun_access_key_secret = xxxxxxxxxxxxxxxxxxxx
aliyun_account_id = 1234567890

You can find the aliyun_access_key_secret and aliyun_access_key_id from https://ak-console.aliyun.com/?#/accesskey. You can also chose to create an Access Key or use sub-account Access Key. You can find the aliyun_account_id from https://account-intl.console.aliyun.com/?#/secure . After creating the credentials file, please make sure to change the credentials field value in serverless.yml to the absolute file path.

See 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

Make sure that you have activated Function Compute and any other dependent services such as RAM, Log Service, API Gateway and OSS before attempting to deploy your function.

  • Deploy your service to Aliyun:

    $ serverless deploy

    If 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 hello
  • Retrieve the LogHub logs generated by your function:

    $ serverless logs --function hello
  • Get information on your deployed functions

    $ serverless info
  • When you no longer needs your service, you can remove the service, functions, along with deployed endpoints and triggers using:

    $ serverless remove

    Note: by default RAM roles and policies created during the deployment are not removed. You can use serverless remove --remove-roles if you do want to remove them.

Change Region

  • Changing the region in provider of serverless.yml:

    provider:
      name: aliyun
      region: cn-hongkong
  • Changing the region in CLI parameters:

    $ serverless deploy --region cn-hongkong

    Note: CLI parameter --region has higher priority than provider, But you have to add this parameter to all the invocations, not only deploy.

Develop

# clone this repo
git clone [email protected]: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 package

License

MIT