Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@tencent-serverless/tencent-scf-beta

2.0.4 • Public • Published

serverless cloud funtion

Deploy scf functions to tencent in seconds with Serverless Components.

 

 

  1. Install
  2. Create
  3. Configure
  4. Deploy
  5. Remove

 

1. Install

$ npm install -g serverless

2. Create

$ mkdir my-function
$ cd my-function

the directory should look something like this:

|- code
  |- index.js
|- serverless.yml
|- .env      # your Tencent SecretId/Key/AppId

Add the access keys of a Tencent CAM Role with AdministratorAccess in the .env file, using this format:

# .env
TENCENT_SECRET_ID=XXX
TENCENT_SECRET_KEY=XXX
  • If you don't have a Tencent Cloud account, you could sign up first.

For this example, you could add the code to index.js file:

'use strict';
exports.main_handler = async (event, context, callback) => {
    console.log("%j", event);
    return "hello world"
};
 

3. Configure

# serverless.yml
 
myFunction:
  component: "@serverless/tencent-scf"
  inputs:
    name: myFunction
    codeUri: ./code
    handler: index.main_handler
    runtime: Nodejs8.9
    region: ap-guangzhou
 
 

4. Deploy

$ sls --debug
 
  DEBUG ─ Resolving the template's static variables.
  DEBUG ─ Collecting components from the template.
  DEBUG ─ Downloading any NPM components found in the template.
  DEBUG ─ Analyzing the template's components dependencies.
  DEBUG ─ Creating the template's components graph.
  DEBUG ─ Syncing template state.
  DEBUG ─ Starting Website Removal.
  DEBUG ─ Removing Website bucket.
  DEBUG ─ Removing files from the "my-bucket-1300415943" bucket.
  DEBUG ─ Removing "my-bucket-1300415943" bucket from the "ap-guangzhou" region.
  DEBUG ─ "my-bucket-1300415943" bucket was successfully removed from the "ap-guangzhou" region.
  DEBUG ─ Finished Website Removal.
  DEBUG ─ Executing the template's components graph.
  DEBUG ─ Compressing function myFunction file to /Users/dfounderliu/Desktop/temp/code/.serverless/myFunction.zip.
  DEBUG ─ Compressed function myFunction file successful
  DEBUG ─ Uploading service package to cos[sls-cloudfunction-ap-guangzhou-code]. sls-cloudfunction-default-myFunction-1572519895.zip
  DEBUG ─ Uploaded package successful /Users/dfounderliu/Desktop/temp/code/.serverless/myFunction.zip
  DEBUG ─ Creating function myFunction
  DEBUG ─ Created function myFunction successful
 
  myFunction: 
    Name:        myFunction
    Runtime:     Nodejs8.9
    Handler:     index.main_handler
    MemorySize:  128
    Timeout:     3
    Region:      ap-guangzhou
    Role:        QCS_SCFExcuteRole
    Description: This is a template function
    UsingCos:    true
 
  6s › myFunction › done
 

5. Remove

$ sls remove --debug
 
  DEBUG ─ Flushing template state and removing all components.
  DEBUG ─ Removed function myFunction successful
 
  1s › myFunction › done
 

New to Components?

Checkout the Serverless Components repo for more information.

Keywords

none

Install

npm i @tencent-serverless/tencent-scf-beta

DownloadsWeekly Downloads

3

Version

2.0.4

License

Apache

Unpacked Size

84.3 kB

Total Files

26

Last publish

Collaborators

  • avatar
  • avatar