@selectel/s8s
v1.1.0
Published
Node.js SDK for Selectel Serverless Functions
Downloads
5
Readme
Serverless cloud functions
Contents
Quick Start
- Install:
npm i @selectel/s8s
- Go to Cloud platform -> All users. Create new user (or use existing one) and add it to your project.
- Go to Cloud platform -> Access. Select user and any region. Click on "Download" button. rc.sh file will be downloaded.
- Set environment variables (you can get them from rc.sh file):
- OS_USERNAME
- OS_PASSWORD (this one isn't stored in rc.sh)
- OS_PROJECT_ID
- OS_PROJECT_DOMAIN_NAME
- OS_USER_DOMAIN_NAME
- Create your own cloud function:
const client = require("@selectel/s8s"); const functionConfig = { action_name: "my_first_function", function_id: null, // will be added later function_name: "main", file_name: "hello.js", limits: { memory: 256 }, module_name: "hello", runtime: "nodejs", version: "12", env_vars: {}, }; client .uploadModule("./hello.js") .then(({ function_id }) => { return client.startCreateFunction({ ...functionConfig, ...{ function_id } }); }) .then(() => { client.getFunction(functionConfig.action_name) }) .then(({status}) => { if (status.status === "IN PROGRESS") { // retry get function, until you get status "COMPLETE". This means function is ready for invoke. } }) .then(() => { return client.startInvokeFunction(functionConfig.action_name, {inParams: "test"}) }).then(({activationId}) => { client.getActivationResult(activationId).catch((err) => { // retry getActivationResult if receive 404. It means that invoke hasn't finished yet. }) client.getActivationLogs(activationId).catch((err) => { // retry getActivationResult if receive 404. It means that invoke hasn't finished yet. }) })
Examples
You can see examples of using cloud functions here
Useful
Community
For all questions - [email protected]
Licensing
Serverless is licensed under the APACHE License.