使用无服务器框架通过部署调用 lambda 函数
有没有办法在使用无服务器框架部署后立即调用 lambda 函数.该函数只是创建了 SNS 应用程序,只需要在设置过程中完成一次.我可以使用 serverless 部署阶段 &&serverless invoke --function functionName
但如果函数失败,这不会破坏设置.
Is there a way to invoke a lambda function immediately after deployment using serverless framework. This function just creates the SNS Application, which is required to be done once only during setup.
I can use serverless deploy stage && serverless invoke --function functionName
but that won't tear down the setup if the function fails.
我希望将其作为设置的一部分进行部署.
I want it to be deployed as part of setup.
谢谢
Hooks 可以添加到 Serverless 框架的生命周期事件中.
Hooks can be added to the lifecycle events of the Serverless framework.
我使用了 serverless-plugin-scripts 插件(https://www.npmjs.com/package/serverless-plugin-scripts) 在部署和移除堆栈后调用自定义作业.
I used serverless-plugin-scripts plugin(https://www.npmjs.com/package/serverless-plugin-scripts) to invoke custom jobs after deployment and removal of stack.
这是一个例子 -
custom:
scripts:
hooks:
'deploy:finalize': sls invoke -f functionName &&
'remove:remove': npm run scriptName && sls invoke -f anotherFunctionName
现在,通过serverless deploy
成功部署后,sls invoke -f functionName
被触发.
Now, after successful deployment via serverless deploy
, sls invoke -f functionName
is triggered.
同样,在使用 serverless remove
删除时,npm run scriptName &&sls invoke -f anotherFunctionName
执行.
Similarly, on removal using serverless remove
, npm run scriptName && sls invoke -f anotherFunctionName
executes.
无服务器框架的生命周期事件/命令的完整列表可在此处获得 - https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406
Complete list of Serverless framework's Lifecycle events / commands is available here - https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406