用Aliyun服务搭了个Serverless小Demo,希望对大家有所启发
Github地址, React + Nodejs
How it works
- OSS - Object Storage Service An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world
- API-Gateway API Gateway provides you with high-performance and highly available API hosting services to deploy and release your APIs on Alibaba Cloud products.
- Function Compute A fully hosted and serverless running environment that takes away the need to manage infrastructure such as servers and enables developers to focus on writing and uploading code.
- OTS - Table Store A fully managed NoSQL cloud database service that enables storage of a massive amount of structured and semi-structured data.
Quick Start
-
- npm install @alicloud/fun -g
-
Configuration, there are two ways, choose one of the following
- fun config, just execute this command
- add .env file and remember add it to .gitignore
REGION=cn-shenzhen ACCESS_KEY_ID=xxxxxxxxxxxx ACCESS_KEY_SECRET=xxxxxxxxxx
-
Create a Table Store Instance and Table, the table store address of Aliyun
- Create Instance, the default name is serverless, if you’d like to change it, you need to replace the EnvironmentVariables.InstanceName of the template.yml with yours.
- Create Table, the defualt name is reflection, if you’d like to change it, you need to replace the EnvironmentVariables.InstanceName of the template.yml with yours.
- Add primary keys, id’s type is autoIncrement company Type: INTEGER Name: id Type: INTEGER
-
Fun Deploy
-
Build and Deploy frontend application
- npm build
npm install npm run build
- create OSS buket, make it Public to allow erveryone can visit it.
- import static files to the OSS buket
- Basic Settings -> Static Pages
- Bind Self-Hosted Domain Name(Not necessary)
- npm build