在为我通过 aws-nodejs-typescript-ts 模板创建的项目添加每 2 分钟运行 lambda 的 cron 表达式后尝试执行
serverless deploy
时,我收到此错误:
Resource handler returned message: "Parameter ScheduleExpression is not valid. (Service: EventBridge, Status Code: 400, Request ID: xxx-xxxx-xxx)" (RequestToken: xxx-xxx-xxx-xx, HandlerErrorCode: GeneralServiceException)
这是我的功能配置:
export default {
handler: `${handlerPath(__dirname)}/handler.main`,
events: [
{
http: {
method: 'post',
path: 'hello',
request: {
schemas: {
'application/json': schema,
},
},
},
},
{
schedule: {
rate: ['cron(*/2 * * * *)'],
}
}
],
};
无服务器框架似乎要求速率参数是
string
而不是数组。请尝试以下方法:
export default {
handler: `${handlerPath(__dirname)}/handler.main`,
events: [
{
http: {
method: 'post',
path: 'hello',
request: {
schemas: {
'application/json': schema,
},
},
},
},
{
schedule: {
rate: 'cron(*/2 * * * *)',
}
}
],