使用无服务器框架通过部署调用 lambda 函数 [英] Invoke a lambda function with deployment using serverless framework

查看:45
本文介绍了使用无服务器框架通过部署调用 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

这篇关于使用无服务器框架通过部署调用 lambda 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆