alibaba / funcraft

(have) Fun with Serverless(API Gateway & Function Compute)
MIT License
941 stars 129 forks source link

Node.js Initializer 函数无法在本地环境触发,发布到线上后可以触发 #1095

Open fanmaomao opened 3 years ago

fanmaomao commented 3 years ago

配置的Initializer函数在本地运行时无法触发,发布到线上后可以触发

配置和日志如下:

template.yml

ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
  Puppeteer-service-screenshot:
    Type: 'Aliyun::Serverless::Service'
    Properties:
      Description: Puppeteer screenshot service
    Puppeteer-screenshot:
      Type: 'Aliyun::Serverless::Function'
      Properties:
        Initializer: demo.initializer
        InitializationTimeout: 180
        Handler: demo.handler
        Runtime: nodejs12
        CodeUri: ./
        MemorySize: 512
        Timeout: 120
      Events:
        httpTrigger:
          Type: HTTP
          Properties:
            AuthType: ANONYMOUS
            Methods:
              - GET
              - POST

demo.js

exports.initializer = function (context, callback) {
    console.log('======> demo.js initializer() ');
    callback(null, "");
}

exports.handler = function (request, response, context) {
    console.log('======> demo.js handler() ');

    response.setStatusCode(200);
    response.setHeader('content-type', 'application/json');
    response.send(JSON.stringify({}))
}

fun local start日志:

using template: template.yml
HttpTrigger httpTrigger of Puppeteer-service-screenshot/Puppeteer-screenshot was registered
        url: http://localhost:8000/2016-08-15/proxy/Puppeteer-service-screenshot/Puppeteer-screenshot/
        methods: [ 'GET', 'POST', 'PUT' ]
        authType: ANONYMOUS

function compute app listening on port 8000!

skip pulling image aliyunfc/runtime-nodejs12:1.9.13...
FC Initialize End RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8, Error: Handled function error
FC Invoke Start RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8
load code for handler:demo.handler
2021-03-15T05:37:48.650Z 6e845f13-b0b7-4872-9195-abdb4673c6e8 [verbose] ======> demo.js handler() 
FC Invoke End RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8
Error: Missing header x-fc-initialization-timeout

RequestId: 6e845f13-b0b7-4872-9195-abdb4673c6e8          Billed Duration: 279 ms         Memory Size: 3938 MB    Max Memory Used: 17 MB

fun deploy函数计算控制台日志:

FC Initialize Start RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
load code for handler:demo.initializer
2021-03-15T05:40:01.316Z c02d7abe-a85c-47d0-9b3c-939d4747bf97 [verbose] ======> demo.js initializer() 
FC Initialize End RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
FC Invoke Start RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
load code for handler:demo.handler
2021-03-15T05:40:01.463Z c02d7abe-a85c-47d0-9b3c-939d4747bf97 [verbose] ======> demo.js handler() 
FC Invoke End RequestId: c02d7abe-a85c-47d0-9b3c-939d4747bf97
DevDengChao commented 3 years ago

See : https://github.com/alibaba/funcraft/pull/1089, https://github.com/alibaba/funcraft/pull/1102

ITHcc commented 3 years ago

See : #1095, #1102

我在本地要如何更新呢

DevDengChao commented 3 years ago

See : #1089, #1102

我在本地要如何更新呢

设置环境变量 FC_DOCKER_VERSION 为 latest 参考: https://github.com/DevDengChao/aliyun-fc-nodejs12-runtime-initializer-not-invoked-sample-project