未调用无服务器框架 WarmUp 插件
Serverless framework WarmUp plugin not being called
我尝试将 WarmUp 无服务器插件集成到我的项目中。但是,我认为它不起作用。我在 lambda 的 CloudWatch 日志组中没有看到来自 WarmUp 的调用,并且 lambda 在闲置一段时间后确实需要预热时间。
我的配置如下:
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);
有什么我可以检查的吗?非常感谢任何suggestions/directions。
谢谢
首先,请将插件从provider
中移出
plugins:
- serverless-plugin-warmup
provider:
...
我尝试将 WarmUp 无服务器插件集成到我的项目中。但是,我认为它不起作用。我在 lambda 的 CloudWatch 日志组中没有看到来自 WarmUp 的调用,并且 lambda 在闲置一段时间后确实需要预热时间。
我的配置如下:
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);
有什么我可以检查的吗?非常感谢任何suggestions/directions。
谢谢
首先,请将插件从provider
plugins:
- serverless-plugin-warmup
provider:
...