Home Archives Categories Tags

Aliyun Function Compute Demo

发布时间: 更新时间: 总字数:1260 阅读时间:3m 作者: 分享

函数计算(Function Compute)是一个事件驱动的全托管 Serverless 计算服务,您无需管理服务器等基础设施,只需编写代码并上传,函数计算会为您准备好计算资源,并以弹性、可靠的方式运行您的代码。


npm install @alicloud/fun -g
# or
brew install fun
  • 版本:
# fun --version
  • Help
# fun --help
Usage: fun [options] [command]

The fun command line provides a complete set of commands to define, develop,
test serverless applications locally, and deploy them to the Alibaba Cloud.

  --version       output the version number
  -v, --verbose   verbose output
  -h, --help      display help for command

  config          Configure the fun
  init            Initialize a new fun project
  install         Install dependencies which are described in fun.yml
  build           Build the dependencies
  local           Run your serverless application locally
  edge            Run your serverless application at edge
  validate        Validate a fun template
  deploy          Deploy a fun application
  nas             Operate NAS file system
  package         Package a Function Compute application
  invoke          Remote invoke function
  help [command]  display help for command


# fun config
? Aliyun Account ID 31446019
? Aliyun Access Key ID ***********Xank
? Aliyun Access Key Secret ***********fJo5
? Default region name cn-hangzhou
? 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? Yes
? Use custom endpoint? No



# fun deploy -y
current folder is not a fun project.
Fun detected your application doesn't listen on '' in /Users/xiexianbin/work/code/go/src/github.com/xiexianbin/x-lego/main.go
Fun will replace your addr to '', and also backup your origin file /Users/xiexianbin/work/code/go/src/github.com/xiexianbin/x-lego/main.go to /Users/xiexianbin/work/code/go/src/github.com/xiexianbin/x-lego/main.go.bak
? Are your sure? Yes
You must use 'GOARCH=amd64 GOOS=linux go build -ldflags "-s -w"' to recompile your project every time before using fun deploy.
? Let Fun exec this command now for you? Yes
Executing command 'GOARCH=amd64 GOOS=linux go build -ldflags "-s -w"'...

Generating template.yml...
Generate Fun project successfully!

========= Fun will use 'fun deploy' to deploy your application to Function Compute! =========
(node:19760) Warning: Accessing non-existent property 'validateParameters' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
using region: cn-hangzhou
using accountId: ***********6019
using accessKeyId: ***********Xank
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            │
│ x-lego      │ Aliyun::Serverless::Service  │ Add    │ Description         │
│             │                              │        │ Handler             │
│             │                              │        ├─────────────────────┤
│             │                              │        │ Runtime             │
│             │                              │        ├─────────────────────┤
│             │                              │        │ CodeUri             │
│ x-lego      │ Aliyun::Serverless::Function │ Add    ├─────────────────────┤
│             │                              │        │ MemorySize          │
│             │                              │        ├─────────────────────┤
│             │                              │        │ InstanceConcurrency │
│             │                              │        ├─────────────────────┤
│             │                              │        │ Timeout             │
│             │                              │        │ AuthType            │
│ httpTrigger │ HTTP                         │ Add    ├─────────────────────┤
│             │                              │        │ Methods             │

Waiting for service x-lego to be deployed...
	Waiting for function x-lego to be deployed...
		Waiting for packaging function x-lego code...
		The function x-lego has been packaged. A total of 808 files were compressed and the final size was 6.9 MB
		Waiting for HTTP trigger httpTrigger to be deployed...
		triggerName: httpTrigger
		methods: [ 'GET', 'POST', 'PUT' ]
		trigger httpTrigger deploy success
	function x-lego deploy success
service x-lego deploy success

Detect 'DomainName:Auto' of custom domain 'Domain'
Request a new temporary domain ...
The assigned temporary domain is http://37785285-31446019.test.functioncompute.com,expired at 2020-12-22 23:01:25, limited by 1000 per day.
Waiting for custom domain Domain to be deployed...
custom domain Domain deploy success


fun init -n demo


cd demo
fun local invoke demo