AWS Functions

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38129062/article/details/88389839

配置

无服务器服务中的所有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

猜你喜欢

转载自blog.csdn.net/qq_38129062/article/details/88389839
AWS