AWS Functions

配置

无服务器服务中的所有Lambda函数都可以在属性serverless.yml下找到functions

# serverless.yml
service: myService

provider:
  name: aws
  runtime: nodejs6.10
  memorySize: 512 #可选,单位为MB,默认值为1024
  timeout: 10 #可选,以秒为单位,默认值为6
  versionFunctions: false#可选,默认为真
  tracing:
    lambda: true #可选,启用对所有函数的跟踪(可以为true(true等于'active')'active'或'passthrough')

functions:
  hello:
    handler: handler.hello #必需,在AWS lambda中设置处理程序
    name: ${self:provider.stage}-lambdaName #可选,已部署lambda名称
    description: Description of what the lambda function does #可选,说明发布到AWS
    runtime: python2.7#可选覆盖,默认为提供程序运行时
    memorySize: 512 #可选,单位为MB,默认值为1024
    timeout: 10 #可选,以秒为单位,默认值为6
    reservedConcurrency: 5 #此函数的可选保留并发限制。默认情况下,AWS使用帐户并发限制
    tracing: passthrough可选,覆盖,可以是'active'或'passthrough'

该handler属性指向包含要在函数中运行的代码的文件和模块。

// handler.js
module.exports.functionOne = function(event, context, callback) {}

您可以在此属性中添加任意数量的函数。

# serverless.yml

service: myService

provider:
  name: aws
  runtime: nodejs6.10

functions:
  functionOne:
    handler: handler.functionOne
    description: optional description for your Lambda
  functionTwo:
    handler: handler.functionTwo
  functionThree:
    handler: handler.functionThree

您的函数可以从provider属性继承其设置。

# serverless.yml
service: myService

provider:
  name: aws
  runtime: nodejs6.10
  memorySize: 512 # will be inherited by all functions

functions:
  functionOne:
    handler: handler.functionOne

或者您可以在功能级别指定属性。

# serverless.yml
service: myService

provider:
  name: aws
  runtime: nodejs6.10

functions:
  functionOne:
    handler: handler.functionOne
    memorySize: 512 # function specific

您可以指定一组函数,如果将函数分离到不同的文件,这将非常有用:

# serverless.yml
...

functions:
  - ${file(../foo-functions.yml)}
  - ${file(../bar-functions.yml)}
# foo-functions.yml
getFoo:
  handler: handler.foo
deleteFoo:
  handler: handler.foo
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值