
# 函数
如果您以华为云函数工作流作为提供商，则服务的所有函数都属于华为云函数工作流中的函数。
#### 配置
您的Serverless服务中有关华为云函数工作流的所有内容都可以在functions属性下的serverless.yml中找到。
```
# serverless.yml
service: fg-service
provider:
  name: huawei
plugins:
  - serverless-huawei-functions
functions:
  first:
    handler: index.handler
```
#### 执行入口
handler属性应该是您在入口文件中导出的函数名称。
例如，当您导出函数并以index.js中的handler命名时，您的handler应该是handler: index.handler。
```
// index.js
exports.handler = (event, context, callback) => {};
```
#### 内存大小和超时
函数的memorySize和timeout可以在提供商或函数层面指定。提供商层面的定义允许所有函数共享此配置，而函数层面的定义意味着此配置仅对当前函数有效。
如果未指定，默认memorySize为256MB，timeout为30s。
```
# serverless.yml
provider:
  memorySize: 512
  timeout: 90
functions:
  first:
    handler: first
  second:
    handler: second
    memorySize: 256
    timeout: 60
```
#### 执行入口签名
事件执行入口的签名如下：
```
function (event, context) { }
```
- **event**
  如果函数由指定的APIG事件触发，则传递给执行入口的event如下：
  ```
  // JSON.parse(event)
  {
    events: {
      "body": "",
      "requestContext": {
          "apiId": "xxx",
          "requestId": "xxx",
          "stage": "RELEASE"
      },
      "queryStringParameters": {
          "responseType": "html"
      },
      "httpMethod": "GET",
      "pathParameters": {},
      "headers": {
          "accept-language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
          "accept-encoding": "gzip, deflate, br",
          "x-forwarded-port": "443",
          "x-forwarded-for": "xxx",
          "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
          "upgrade-insecure-requests": "1",
          "host": "xxx",
          "x-forwarded-proto": "https",
          "pragma": "no-cache",
          "cache-control": "no-cache",
          "x-real-ip": "xxx",
          "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0"
      },
      "path": "/apig-event-template",
      "isBase64Encoded": true
    }
  }
  ```
  

- **context**
  context参数包含有关函数的运行时信息。例如：请求ID、临时AK、函数元数据。具体详情请参见[开发事件函数](https://support.huaweicloud.com/devg-functiongraph/functiongraph_02_0410.html)。
  
 
