Operation Scenarios
The COS component is one of the basic components in the serverless-tencent
component library. Through this component, you can create, configure, and manage COS buckets with speed and ease.
Prerequisites
You have installed Node.js (v8.6 or above; v10.0 or above is recommended). Directions
Installation
Install Serverless through npm:
npm install -g serverless
If you have already installed Serverless Framework, you can run the following command to upgrade it to the latest version:
Configuration
Create the serverless.yml
file locally and configure it as follows:
org: orgDemo
app: appDemo
stage: dev
component: cos
name: cosDemo
inputs:
bucket: my-bucket
region: ap-guangzhou
Deployment
Deploy by running the following command, and the information below will be returned:
[root@iZh8dhuyhmexn3Z demo]
serverless ⚡ framework
Action: "deploy" - Stage: "dev" - App: "appDemo" - Instance: "cosDemo"
region: ap-guangzhou
bucket: my-bucket-xxxxxxx
url: http://my-bucket-xxxxxxx.cos.ap-guangzhou.myqcloud.com
Full details: https://serverless.cloud.tencent.com/instances/appDemo%3Adev%3AcosDemo
3s › cosDemo › Success
Removal
Run the sls remove
command to remove the deployed bucket, and the following information will be returned:
[root@iZh8dhuyhmexn3Z demo]
serverless ⚡ framework
Action: "remove" - Stage: "dev" - App: "appDemo" - Instance: "cosDemo"
3s › cosDemo › Success
Account configuration (optional)
Currently, you can scan a QR code to log in to the CLI by default. If you want to configure persistent environment variables/key information, you can also create a local .env
file:
Configure Tencent Cloud's SecretId
and SecretKey
information in the .env
file and save it:
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123
Note:
If you don't have a Tencent Cloud account yet, please sign up first. If you already have a Tencent Cloud account, you can get SecretId
and SecretKey
in API Key Management.
Was this page helpful?