Cloud Native 20 min read

Quick Start with Serverless Devs: Install, Key Management, and Yaml Best Practices

This guide walks you through installing the Serverless Devs CLI, configuring Alibaba Cloud access keys via interactive prompts, command‑line flags, or environment variables, explains key‑usage safety and alias design, and details Yaml syntax, variable handling, service ordering, and custom actions for seamless serverless application deployment.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Quick Start with Serverless Devs: Install, Key Management, and Yaml Best Practices

Install Serverless Devs CLI

Ensure Node.js (>=10.8.0) and npm are installed, then run: npminstall @serverless-devs/s -g Verify the installation with s -v. Example output:

@serverless-devs/s:2.0.89, @serverless-devs/core:0.1.7, darwin‑x64, node‑v12.15.0

Configure Access Keys

Serverless Devs requires an Alibaba Cloud AccessKeyID and AccessKeySecret. Obtain them from the Alibaba Cloud console (https://usercenter.console.aliyun.com/#/manage/ak).

Interactive configuration

Run s config add and follow the prompts:

? Please select a template: Alibaba Cloud(alibaba)
🧭Refer to the document for alibaba key: http://config.devsapp.net/account/alibaba
? AccessKeyID (enter your ID)
? AccessKeySecret (enter your secret)
? Please create alias for key pair. If not, press Enter
   Alias: alibaba-access   AccountID: <em>your‑account‑id</em>
   AccessKeyID: <em>your‑id</em>
   AccessKeySecret: <em>your‑secret</em>
Configuration successful

Verify with s config get -a alibaba-access.

Non‑interactive configuration

s configadd --AccessKeyID myAccessKeyID --AccessKeySecret myAccessKeySecret -a demo
Alias: demo
AccountID: myAccountID
AccessKeyID: myAccessKeyID
AccessKeySecret: myAccessKeySecret
Configuration successful

Environment‑variable configuration

Direct config add with env vars

s config add -a default-aliyun -kl AccessKeyID,AccessKeySecret -il ${ALIBABA_CLOUD_ACCESS_KEY_ID},${ALIBABA_CLOUD_ACCESS_KEY_SECRET}

Named JSON env‑var Define an environment variable (e.g., default_serverless_devs_access) with value

{"AccessKeyID":"temp_accesskeyid","AccessKeySecret":"temp_accesskeysecret"}

and reference it by alias.

Key‑Usage Considerations

Security : AccessKeys grant full API permissions; store them securely and avoid committing to public repositories. Prefer RAM sub‑users.

Alias design : Use distinct aliases (e.g., alibaba, tencent) to switch between providers or environments without re‑configuring keys.

Usage : Specify an alias with -a/--access on CLI commands (e.g., s deploy -a demo) or set access in the Yaml file for application‑wide or service‑specific key selection.

Yaml Specification

A Serverless Devs Yaml file describes an application. Key points:

File extensions: .yaml or .yml.

Must follow Yaml 1.2 specification (https://yaml.org/spec/1.2.2/).

Typical naming: s-${ENV}.yaml (e.g., s-prod.yaml).

Default file names are s.yaml (preferred) or s.yml.

Custom template path can be supplied with -t/--template.

Basic structure example:

edition: 1.0.0
name: applicationName
access: xxx-account1

vars:
  Key: Value

services:
  ServiceName:
    access: xxx-account1   # optional if same as project
    component: componentName
    props: serviceProp
    actions: serviceActions

Variable references: ${env(VARIABLE)} – environment variable. ${file(PATH)} – external file content. ${vars.*} – global vars. ${projectName.props.*} – other project props. ${projectName.output.*} – other project outputs.

Service order

If multiple services exist, Serverless Devs resolves dependencies first, then deploys dependent services before independent ones, preserving the order defined in the Yaml.

Actions

Custom pre‑ and post‑commands can be defined:

actions:
  pre-deploy:
    - run: s exec -- publish
      path: ./backend_src
    - run: s build
      path: ./backend_src
  post-deploy:
    - run: s clean
      path: ./frontend_src

During s deploy, the CLI executes pre‑commands, then the component’s deploy method, followed by post‑commands.

Operation Modes

Yaml mode : Requires a descriptor file ( s.yaml / s.yml) or a template path. All parameters are read from the Yaml.

CLI mode : Directly invoke component methods without a Yaml file (e.g.,

s cli devsapp/demo --region cn-hangzhou --service-name myService

). Yaml‑style properties can be passed via -p/--prop JSON strings.

Example Application

Sample s.yaml for a full‑stack app:

name: FullStack
edition: 1.0.0
access: xxx-account1

services:
  nextjs-portal:
    component: vue-component
    props:
      src: ./frontend_src
      url: url
    actions:
      pre-deploy:
        - run: s exec -- publish
          path: ./backend_src
        - run: s build
          path: ./backend_src
      post-deploy:
        - run: s clean
          path: ./frontend_src
  assets:
    component: static
    props:
      cache-control: "public, max-age=604800, immutable"
      www: "./public"
  express-blog:
    component: express
    props:
      app: ./express-blog
      url: ${vars.domain}
    actions:
      pre-deploy:
        - run: npm run build
          path: ./express-blog

Deploy the whole application with s deploy or target a specific service with s nextjs-portal deploy.

Additional Operations

s config get -h

– view stored keys. s config -h – list create, update, delete options.

Use -f to force overwrite an existing alias.

Component‑specific commands are exposed through the CLI. Exit codes: 0 success, 100 method not found, 101 execution error.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLICloud NativeServerlessYAMLkey management
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.