This topic describes how to deploy a Koa.js application to Function Compute. Function
Compute provides a method different from traditional deployment methods. You can deploy
a traditional Koa.js application to Function Compute and use the application for production
without performing operations such as purchasing a server. The deployed Koa.js application
can use the auto scaling, pay-as-you-go, and O&M-free features of Function Compute.
Prerequisites
The following operations are complete:
Procedure
- Run the following command in the specified directory to initialize a project:
s init devsapp/start-koa -d start-koa
The
-d parameter specifies the project name. In this example, the project name is start-koa.
Note Skip this step if the item exists.
Sample command output:
Serverless Awesome: https://github.com/Serverless-Devs/package-awesome
devsapp!start-koa@0.0.8.zip file decompression completed
please select credential alias default
_ __
| | / /
| |/ / ___ __ _
| \ / _ \ / _` |
| |\ \ (_) | (_| |
\_| \_/\___/ \__,_|
Welcome to the start-koa application
This application requires to open these services:
FC : https://fc.console.aliyun.com/
ACR: https://cr.console.aliyun.com/
This application can help you quickly deploy the Koa project:
Full yaml configuration: https://github.com/devsapp/koa#%E5%AE%8C%E6%95%B4yaml
Koa development docs : https://www.koajs.com.cn/
This application homepage: https://github.com/devsapp/start-koa
Thanks for using Serverless-Devs
You could [cd /test/start-koa] and enjoy your serverless journey!
If you need help for this example, you can use [s -h] after you enter folder.
Document Star: https://github.com/Serverless-Devs/Serverless-Devs
- Run the following command to go to the project directory:
- Run the following command to deploy the project:
s deploy
Sample command output:
[2021-08-30T15:40:24.764] [INFO ] [S-CLI] - Start ...
[2021-08-30T15:40:24.773] [INFO ] [S-CLI] - Start the pre-action
[2021-08-30T15:40:24.773] [INFO ] [S-CLI] - Action: npm install --production
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN start-koa@1.0.0 No description
npm WARN start-koa@1.0.0 No repository field.
added 44 packages from 23 contributors in 1.399s
3 packages are looking for funding
run `npm fund` for details
[2021-08-30T15:40:26.558] [INFO ] [S-CLI] - End the pre-action
devsapp!koa@0.1.7.zip file decompression completed
Using web framework type: nas, If you want to deploy with container, you can [s cli fc-default set web-framework container] to switch.
[2021-08-30T15:40:40.923] [WARN ] [KOA] - The startup file is not found, create a [start.sh] as the startup file.
Using web framework type: nas, If you want to deploy with container, you can [s cli fc-default set web-framework container] to switch.
(node:10777) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
End of request
Deployed.
End of request
[2021-08-30T15:40:47.580] [INFO ] [FC-DEPLOY] - Using region: cn-shenzhen
[2021-08-30T15:40:47.581] [INFO ] [FC-DEPLOY] - Using access alias: default
[2021-08-30T15:40:47.581] [INFO ] [FC-DEPLOY] - Using accessKeyID: 188077086902****
[2021-08-30T15:40:47.581] [INFO ] [FC-DEPLOY] - Using accessKeySecret: ldHUiJLoGto****
Using fc deploy type: sdk, If you want to deploy with pulumi, you can [s cli fc-default set deploy-type pulumi] to switch.
[2021-08-30T15:40:48.291] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-koa exists
[2021-08-30T15:40:48.643] [INFO ] [FC-DEPLOY] - Setting role: AliyunFCDefaultRole
[2021-08-30T15:40:48.950] [INFO ] [RAM] - Checking Role AliyunFCDefaultRole exists
[2021-08-30T15:40:49.118] [INFO ] [RAM] - Updating role: AliyunFCDefaultRole
[2021-08-30T15:40:49.218] [INFO ] [RAM] - Checking Plicy AliyunFCDefaultRolePolicy exists
[2021-08-30T15:40:49.353] [INFO ] [FC-DEPLOY] - Using vpcConfig: auto: fc will try to generate related vpc resources automatically
[2021-08-30T15:40:50.147] [INFO ] [VPC] - Getting vpc: fc-deploy-component-generated-vpc-cn-shenzhen
[2021-08-30T15:40:50.308] [INFO ] [VPC] - Getting vswitch: fc-deploy-component-generated-vswitch-cn-shenzhen
[2021-08-30T15:40:50.443] [INFO ] [VPC] - Getting securityGroup: fc-deploy-component-generated-securityGroup-cn-shenzhen
[2021-08-30T15:40:50.626] [INFO ] [FC-DEPLOY] - Generated vpcConfig:
securityGroupId: sg-wz92ctigpi221smc****
vSwitchId: vsw-wz9qnuult4q5g4f7n****
vpcId: vpc-wz9x9bzs0wtvjgt6n****
[2021-08-30T15:40:50.627] [INFO ] [FC-DEPLOY] - Using nasConfig: auto: fc will try to generate related nas file system automatically
[2021-08-30T15:41:15.512] [INFO ] [FC-DEPLOY] - Generated nasConfig:
groupId: 10003
mountPoints:
- fcDir: /mnt/auto
nasDir: /serverless-devs-koa
serverAddr: example.com
userId: 10003
[2021-08-30T15:41:15.514] [INFO ] [FC-DEPLOY] - Checking Function koa exists
[2021-08-30T15:41:15.617] [WARN ] [FC-DEPLOY] - Image registry.cn-shenzhen.aliyuncs.com/web-framework/nodejs12:0.0.1 dose not exist locally.
Maybe you need to run 's build' first if it dose not exist remotely.
[2021-08-30T15:41:15.621] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-koa exists
[2021-08-30T15:41:15.719] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-koa exists
[2021-08-30T15:41:15.824] [INFO ] [FC-DEPLOY] - Creating service: serverless-devs-koa
[2021-08-30T15:41:15.824] [INFO ] [FC-DEPLOY] - Creating function: koa
[2021-08-30T15:41:15.825] [INFO ] [FC-DEPLOY] - Creating triggers: ["serverless-devs-koa"]
Make service serverless-devs-koa success.
Make function serverless-devs-koa/koa success.
Make trigger serverless-devs-koa/koa/serverless-devs-koa success.
[2021-08-30T15:41:18.879] [INFO ] [FC-DEPLOY] - Checking Service serverless-devs-koa exists
[2021-08-30T15:41:18.950] [INFO ] [FC-DEPLOY] - Checking Function koa exists
[2021-08-30T15:41:19.107] [INFO ] [FC-DEPLOY] - Checking Trigger serverless-devs-koa exists
[2021-08-30T15:41:19.323] [INFO ] [FC-DEPLOY] - Creating custom domain: koa.serverless-devs-koa.188077086902****.cn-shenzhen.fc.devsapp.net
[2021-08-30T15:41:20.017] [INFO ] [FC-DOMAIN] - Creating custom domain: koa.serverless-devs-koa.188077086902****.cn-shenzhen.fc.devsapp.net
There is auto config in the service: serverless-devs-koa
[2021-08-30T15:41:20.303] [INFO ] [WEB-FRAMEWORK] - nas component get src is: ./src
Packing ...
Package complete.
Start uploading file: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-koa/koa/src.zip
File uploaded successfully: /mnt/2bfb748534-tpm20-cn-shenzhen/serverless-devs-koa/koa/src.zip
upload done
[2021-08-30T15:41:54.207] [INFO ] [FC-NAS] - unzipping file
[2021-08-30T15:41:56.324] [INFO ] [FC-NAS] - unzip done
Try container acceleration
framework-test:
region: cn-shenzhen
serviceName: serverless-devs-koa
functionName: koa
customDomains:
- http://koa.serverless-devs-koa.188077086902****.cn-shenzhen.fc.devsapp.net
Result
After the project is deployed, you can view the temporary domain name generated by
Function Compute in the execution output. The temporary domain name can be used to
access the newly deployed application. For example, run the following command to access
the application:
curl http://koa.serverless-devs-koa.188077086902****.cn-shenzhen.fc.devsapp.net
Note The temporary domain name is used only for demonstration and development purposes.
It is valid for a limited period of time. You must use a domain name that has obtained
an Internet Content Provider (ICP) filing from Alibaba Cloud for production. For more
information, see
Configure a custom domain name.