Aws lambda 未调用无服务器框架预热插件
我试图将WarmUp无服务器插件集成到我的项目中。不过,我相信这是行不通的。我在lambda的CloudWatch日志组中没有看到来自预热的调用,并且lambda在空闲一段时间后确实需要预热时间 我的配置如下:Aws lambda 未调用无服务器框架预热插件,aws-lambda,serverless-framework,serverless,Aws Lambda,Serverless Framework,Serverless,我试图将WarmUp无服务器插件集成到我的项目中。不过,我相信这是行不通的。我在lambda的CloudWatch日志组中没有看到来自预热的调用,并且lambda在空闲一段时间后确实需要预热时间 我的配置如下: service: ${file(./${env:DEPLOY_FILE_NAME}):service} provider: name: aws custom: roleName: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):roleN
service: ${file(./${env:DEPLOY_FILE_NAME}):service}
provider:
name: aws
custom:
roleName: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):roleName}
profileName: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):profileName}
bundle:
ignorePackages:
- pg-native
warmup:
enabled: true
events:
- schedule: rate(5 minutes)
prewarm: true
plugins:
- pluginHandler
- serverless-plugin-warmup
runtime: nodejs12.x
iamRoleStatements:
- Effect: 'Allow'
Action:
- 'lambda:InvokeFunction'
Resource:
- Fn::Join:
- ':'
- - arn:aws:lambda
- Ref: AWS::Region
- Ref: AWS::AccountId
- function:${self:service}-${opt:stage, self:provider.stage}-*
cfLogs: true
stage: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):stage}
region: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):region}
memorySize: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):memorySize}
timeout: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):timeout}
keepWarm: false
useApigateway: true
package:
exclude:
${file(./${env:DEPLOY_FILE_NAME}):exclude}
functions:
lambdaHandler:
handler: ${file(./${env:DEPLOY_FILE_NAME_STAGE}):handler}
events:
${file(./${env:DEPLOY_FILE_NAME}):events}
warmup:
enabled: true
lambda代码:
const awsLambdaFastify = require('aws-lambda-fastify');
const app = require('./index');
const proxy = awsLambdaFastify(app);
const fastify = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
proxy(event, context, callback);
};
const warm = func => (event, context, callback) => {
if (event.source === 'serverless-plugin-warmup') {
return callback(null, 'Lambda is warm!');
}
return func(event, context, callback);
};
exports.handler = warm(fastify);
有什么我可以查的吗?非常感谢您的任何建议/指导
谢谢首先,请将插件从
提供商
plugins:
- serverless-plugin-warmup
provider:
...
您有
keepWarm:false
。这可能是问题吗?看起来不错。不幸的是,将默认的keepWarm更改为true没有帮助。我看到您还没有定义Lambda负载,但是它仍然应该使用默认值调用,即使它可能会出错。如果创建了调用事件(每5分钟一次),您是否在AWS控制台中进行了检查?我不知道如何在控制台中进行检查,但从CloudWatch日志可以清楚地看出,没有预热事件。不确定定义有效负载是什么意思。Warmup包装lambda,例如handler转到Warmup,Warmup检查源,并在源是Warmup调用时作出反应。它在文档中。您需要将事件计划更改为并发预热:启用:true#默认情况下是否预热函数预预热:true#在部署Lambda并发:5后立即运行预热