阿里云函数计算 VSCode 使用,及部署 Docusaurus
使用简介
产品页开通服务。使用流程,如下:

新手示例,如下:


创建函数
阿里云提供了如下几种方式创建函数:
以下为使用 VSCode 插件创建函数。
前提准备
安装软件
安装插件
插件: Aliyun Serverless VSCode Extension
VSCode 插件市场搜索 "aliyun" ,安装:

左侧边栏,打开插件,绑定账户:

依次输入 Account ID, AccessKey ID, AccessKey Secret, Account Alias 。
绑定后, "REMOTE RESOURCES" 可以看到该账户的云端服务与函数列表。
本地创建
"LOCAL RESOURCES" 面板 "+" 创建函数:

输入内容:
service name: demo
function name: test
function runtime: nodejs12
function type: NORMAL (Event Trigger)
本地运行
函数名称上 "Local Run" 运行:

函数日志,输出在终端。
远程部署
"LOCAL RESOURCES" 面板 "Deploy" 部署函数:

"REMOTE RESOURCES" 可查看部署的函数。
或者到阿里云函数计算控制台查看:

部署 Docusaurus
环境准备
安装 Funcraft
Funcraft 是函数计算提供的一种命令行工具,通过该工具,您可以便捷地管理函数计算、API网关、日志服务等资源。通过一个资源配置文件 template.yml , Funcraft 即可协助您进行开发、构建、部署操作。
npm 安装:
npm install @alicloud/fun -g
fun 版本:
❯ fun --version
3.6.18
fun 配置:
❯ fun config
? Aliyun Account ID ***********
? Aliyun Access Key ID ***********AmpG
? Aliyun Access Key Secret ***********XZlY
? Default region name cn-shanghai
? The timeout in seconds for each SDK client invoking 60
? The maximum number of retries for each SDK client 3
? Allow to anonymously report usage statistics to improve the tool over time? Ye
s
? Use custom endpoint? No
创建应用
npx @docusaurus/init@next init my-site classic
运行:
cd my-site
yarn start
效果:

部署应用
❯ cd my-site
初始化:
❯ fun init
? Select a template to init http-trigger-nodejs12
? You've created /users/ikuokuo/start-serverless/my-site before. Is it okay to override it? Yes
Start rendering template...
+ /users/ikuokuo/start-serverless/my-site
+ /users/ikuokuo/start-serverless/my-site/.funignore
+ /users/ikuokuo/start-serverless/my-site/index.js
+ /users/ikuokuo/start-serverless/my-site/template.yml
finish rendering template.
删除 index.js。
rm index.js
修改 template.yml:
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
my-site:
Type: 'Aliyun::Serverless::Service'
Properties:
Description: 'helloworld'
my-site:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: custom
CodeUri: './'
MemorySize: 1024
InstanceConcurrency: 5
Timeout: 120
Events:
httpTrigger:
Type: HTTP
Properties:
AuthType: ANONYMOUS
Methods: ['GET', 'POST', 'PUT']
Domain:
Type: Aliyun::Serverless::CustomDomain
Properties:
DomainName: Auto
Protocol: HTTP
RouteConfig:
Routes:
"/*":
ServiceName: my-site
FunctionName: my-site
创建 bootstrap:
❯ cat <<EOF >bootstrap
#!/usr/bin/env bash
export PORT=9000
npm run serve -- --port \$PORT
# yarn serve --port \$PORT
EOF
❯ chmod a+x bootstrap
Something is already running on port: https://github.com/facebook/docusaurus/issues/3505.
Checknpx docusaurus --version>= 2.0.0-alpha.66 !
编译:
yarn build
部署:
❯ fun deploy
using template: template.yml
using region: cn-shanghai
using accountId: ***********
using accessKeyId: ***********AmpG
using timeout: 60
Collecting your services information, in order to caculate devlopment changes...
Resources Changes(Beta version! Only FC resources changes will be displayed):
┌─────────────┬──────────────────────────────┬────────┬─────────────────────┐
│ Resource │ ResourceType │ Action │ Property │
├─────────────┼──────────────────────────────┼────────┼─────────────────────┤
│ my-site │ Aliyun::Serverless::Service │ Add │ Description │
├─────────────┼──────────────────────────────┼────────┼─────────────────────┤
│ │ │ │ Handler │
│ │ │ ├─────────────────────┤
│ │ │ │ Runtime │
│ │ │ ├─────────────────────┤
│ │ │ │ CodeUri │
│ my-site │ Aliyun::Serverless::Function │ Add ├─────────────────────┤
│ │ │ │ MemorySize │
│ │ │ ├─────────────────────┤
│ │ │ │ InstanceConcurrency │
│ │ │ ├─────────────────────┤
│ │ │ │ Timeout │
├─────────────┼──────────────────────────────┼────────┼─────────────────────┤
│ │ │ │ AuthType │
│ httpTrigger │ HTTP │ Add ├─────────────────────┤
│ │ │ │ Methods │
└─────────────┴──────────────────────────────┴────────┴─────────────────────┘
? Please confirm to continue. Yes
Waiting for service my-site to be deployed...
Waiting for function my-site to be deployed...
Waiting for packaging function my-site code...
The function my-site has been packaged. A total of 29625 files were compressed and the final size was 37.05 MB
Waiting for HTTP trigger httpTrigger to be deployed...
triggerName: httpTrigger
methods: [ 'GET', 'POST', 'PUT' ]
trigger httpTrigger deploy success
function my-site deploy success
service my-site deploy success
Detect 'DomainName:Auto' of custom domain 'Domain'
Request a new temporary domain ...
The assigned temporary domain is http://33146085-1117460590419785.test.functioncompute.com,expired at 2020-10-18 23:59:03, limited by 1000 per day.
Waiting for custom domain Domain to be deployed...
custom domain Domain deploy success
访问 http://33146085-1117460590419785.test.functioncompute.com:

结语
欢迎关注 GoCoding 公众号,分享日常 Coding 中实用的小技巧、小知识!
阿里云函数计算 VSCode 使用,及部署 Docusaurus的更多相关文章
- 阿里云函数计算上部署.NET Core 3.1
使用阿里云ECS或者其他常见的VPS服务部署应用的时候,需要手动配置环境,并且监测ECS的行为,做补丁之类的,搞得有点复杂.好在很多云厂商(阿里云.Azure等)提供了Serverless服务,借助于 ...
- 独家对话阿里云函数计算负责人不瞋:你所不知道的 Serverless
作者 | 杨丽 出品 | 雷锋网产业组 "Serverless 其实离我们并没有那么遥远". 如果你是一名互联网研发人员,那么极有可能了解并应用过 Serverless 这套技术体 ...
- 阿里云函数计算发布新功能,支持容器镜像,加速应用 Serverless 进程
我们先通过一段视频来看看函数计算和容器相结合后,在视频转码场景下的优秀表现.点击观看视频 >> FaaS 的门槛 Serverless 形态的云服务帮助开发者承担了大量复杂的扩缩容.运维. ...
- 阿里云函数计算 .NET Core 初体验
体验了一波阿里云函数计算, 已支持 .NET Core 2.1, 那么按照惯例, 来写个 "Hello World" 吧. 作者注: 开发环境 Windows 10 & V ...
- 荣获“5G MEC优秀商用案例奖”,阿里云边缘计算发力新零售
4月24日,在中国联通合作伙伴大会的 “5G MEC(Mobile Edge Computing,移动边缘计算)边缘云赋能行业数字化转型”分论坛上,阿里云“基于5G边缘计算的新零售应用案例”荣获201 ...
- 阿里云服务器Windows Server 2008/2012部署Office Web Server 2013
以前成功将Office Web Server 2013部署在了本地服务器上,此次是将Office Web Server 2013部署在阿里云服务器Windows Server 2008和2012上,中 ...
- 如何在IIS上发布网站 在阿里云服务器windows server2012r iis上部署.net网站
如何在IIS上发布网站 本片博客记录一下怎么用IIS发布一个网站,以我自己电脑上一个已经开发完成的网站为例: 1.打开项目 这是我电脑上的一个项目,现在我记录一下将这个项目发布到iis上的整个过程 ...
- 阿里云流计算专场-GitHub上相关文档
阿里云流计算专场-GitHub路径:https://github.com/Alibaba-Technology/hangzhouYunQi2017ppt
- 初码-Azure系列-记一次从阿里云到Azure的迁移和部署
有个客户在阿里云上,这次要迁移到Azure去,手工记一下流水账 原系统信息: 阿里云ECS单Web节点(8核16G,10000IOPS SSD云盘)+阿里云ECS单数据库节点(16核32G,15000 ...
随机推荐
- 对lambda表达式的字节码实现个人理解 - 简单描述
暂且抛开具体的代码实现,谈谈个人的理解. 常规的方法调用,具体由哪条指令来执行,实际都是在JVM的规则中就定下来了,比如构造方法使用invokeSpecial,静态方法使用invokeStatic.现 ...
- devops-jenkins分布式构建
1. devops-jenkins分布式构建 1) 点击系统管理 进入节点管理 2) 点击新建节点 3) 进行节点配置在node节点服务器配置,进行java的安装 [root@nginx-backup ...
- 如何将python下载源地址修改为国内镜像源
(1)在 C:\Users\xxx 下面创建新的目录 pip 文件夹 (2)在 pip目录下创建后缀为ini,名为pip的文件,另存为 (pip.ini) 文件内容设置为:(清华源) [glob ...
- 实验一 HTML基本标签及文本处理
实验一 HTML基本标签及文本处理 [实验目的] 1.掌握利用因特网进行信息游览.搜索,下载网页.图片.文字和文件: 2.对给定的网站,能指出网站的链接结构.目录结构.页面布局方式: 3.掌握HTML ...
- 多测师浅谈 学员实现价值就是我们的幸福_高级讲师肖sir
学员实现价值就是我们的幸福 作为一名资深的IT高级讲师,在传统的行业IT薪资基本都是过万,作为一名IT培训教师,培养出在不同领域的测试,并且接触各种各样的产品,目前市场流行的比如银行业务系统,语音类系 ...
- MeteoInfoLab脚本示例:添加南海脚图
添加南海脚图实际上就是增加一个地图坐标系(Axesm),在用axesm函数创建地图坐标系的时候可以指定position参数(即位置和大小),第1和第2个参数是坐标系的左下角x, y位置,后两个参数是坐 ...
- 使用 volatile 关键字保证变量可见性和禁止指令重排序
volatile 概述 volatile 是 Java 提供的一种轻量级的同步机制.相比于传统的 synchronize,虽然 volatile 能实现的同步性要差一些,但开销更低,因为它不会引起频繁 ...
- 【学习笔记】陀螺 Treap
以下来自一堆人从食堂走回机房时的 yy \(\Huge{强烈谴责\ \mathrm{s\color{red}{kyh}}\ 看博客不留评论的行为}\) 听说 longdie 要爆砍 FHQ 无旋 Tr ...
- spring boot:使用多个redis数据源(spring boot 2.3.1)
一,什么情况下需要使用多个redis数据源? 为了缓存数据,通常我们会在线上使用多个redis的cluster, 每个cluster中缓存不同的数据,以方便管理. 例如:我们缓存了杂志文章/商品信息/ ...
- Hadoop框架:DataNode工作机制详解
本文源码:GitHub·点这里 || GitEE·点这里 一.工作机制 1.基础描述 DataNode上数据块以文件形式存储在磁盘上,包括两个文件,一个是数据本身,一个是数据块元数据包括长度.校验.时 ...