gpt4 book ai didi

aws-lambda - 无服务器框架 WarmUp 插件未被调用

转载 作者:行者123 更新时间:2023-12-02 19:12:11 26 4
gpt4 key购买 nike

我尝试将 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);

有什么我可以检查的吗?非常感谢任何建议/指示。

谢谢

最佳答案

首先,请将provider中的插件移出

plugins:
- serverless-plugin-warmup
provider:
...

关于aws-lambda - 无服务器框架 WarmUp 插件未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64124942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com