Supported Framework | Document |
Express | |
Koa | |
Egg | |
Next.js | |
Nuxt.js | |
Nest.js | |
Flask | |
Django | |
Laravel |
serverless.yml
file in the project root directory and write the configuration by referring to the following sample. For the full configuration, please see Configuration Document.# serverless.ymlcomponent: http # Component name, which is requiredname: webDemo # Component instance name, which is requiredinputs:region: ap-guangzhou # Function regionsrc: # Deploy the file code under `src`, package it into a zip file, and upload it to the bucketsrc: ./ # The file directory that needs to be packaged locallyexclude: # Excluded files or directories- .env- 'node_modules/**'faas: # Function configurationframework: express # Select the framework. Express is used here as an exampleruntime: Nodejs12.16name: webDemo # Function nametimeout: 10 # Timeout period in secondsmemorySize: 512 # Memory size, which is 512 MB by defaultlayers:- name: layerName # Layer nameversion: 1 # Versionapigw: # # The HTTP component will create an API Gateway service by defaultisDisabled: false # Specify whether to disable automatic API Gateway creationid: service-xxx # API Gateway service ID. If you leave it empty, a gateway will be automatically createdname: serverless # API Gateway service IDapi: # Relevant configuration of the created APIcors: true # Specify whether to allow CORStimeout: 15 # API timeout periodname: apiName # API namequalifier: $DEFAULT # Version associated with the APIprotocols:- http- httpsenvironment: test
sls deploy
in the root directory to deploy. The component will automatically generate the scf_bootstrap
bootstrap file for deployment according to the selected framework.scf_bootstrap
:#!/usr/bin/env bash/var/lang/node12/bin/node app.js
#!/usr/bin/env bash/var/lang/node12/bin/node app.js
#!/var/lang/node12/bin/node/*** Node path in docker: /var/lang/node12/bin/node* As only `/tmp` is readable/writable in SCF, two environment variables need to be modified at startup* `NODE_LOG_DIR` changes the default node write path of `egg-scripts` (~/logs) to `/tmp`* `EGG_APP_CONFIG` changes the default directory of the Egg application to `/tmp`*/process.env.EGG_SERVER_ENV = 'prod';process.env.NODE_ENV = 'production';process.env.NODE_LOG_DIR = '/tmp';process.env.EGG_APP_CONFIG = '{"rundir":"/tmp","logger":{"dir":"/tmp"}}';const { Application } = require('egg');// If you deploy `node_modules` through layers, you need to modify `eggPath`Object.defineProperty(Application.prototype, Symbol.for('egg#eggPath'), {value: '/opt',});const app = new Application({mode: 'single',env: 'prod',});app.listen(9000, '0.0.0.0', () => {console.log('Server start on http://0.0.0.0:9000');});
#!/var/lang/node12/bin/node/*# As the HTTP passthrough function runs based on the docker image, the listening address must be 0.0.0.0, and the port 9000*/const { nextStart } = require('next/dist/cli/next-start');nextStart(['--port', '9000', '--hostname', '0.0.0.0']);
#!/var/lang/node12/bin/node/*# As the HTTP passthrough function runs based on the docker image, the listening address must be 0.0.0.0, and the port 9000*/require('@nuxt/cli').run(['start', '--port', '9000', '--hostname', '0.0.0.0']).catch((error) => {require('consola').fatal(error);require('exit')(2);});
#!/bin/bash# SERVERLESS=1 /var/lang/node12/bin/npm run start -- -e /var/lang/node12/bin/nodeSERVERLESS=1 /var/lang/node12/bin/node ./dist/main.js
#!/bin/bash# As the HTTP passthrough function runs based on the docker image, the listening address must be 0.0.0.0, and the port 9000/var/lang/python3/bin/python3 app.py
#!/bin/bash# As the HTTP passthrough function runs based on the docker image, the listening address must be 0.0.0.0, and the port 9000/var/lang/python3/bin/python3 manage.py runserver 0.0.0.0:9000
#!/bin/bash######################################## Inject environment variables in the serverless environment######################################## Inject the SERVERLESS flagexport SERVERLESS=1# Modify the template compilation cache path, as only `/tmp` is readable/writable in SCFexport VIEW_COMPILED_PATH=/tmp/storage/framework/views# Modify `session` to store it in the memory (array type)export SESSION_DRIVER=array# Output logs to `stderr`export LOG_CHANNEL=stderr# Modify the application storage pathexport APP_STORAGE=/tmp/storage# Initialize the template cache directorymkdir -p /tmp/storage/framework/views# As the HTTP passthrough function runs based on the docker image, the listening address must be 0.0.0.0, and the port 9000# Path of the executable file in the cloud: /var/lang/php7/bin/php/var/lang/php7/bin/php artisan serve --host 0.0.0.0 --port 9000
Was this page helpful?