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.
Thanks
Hooks can be added to the lifecycle events of the Serverless framework.
I used serverless-plugin-scripts plugin(https://www.npmjs.com/package/serverless-plugin-scripts) to invoke custom jobs after deployment and removal of stack.
Here is an example -
custom:
scripts:
hooks:
'deploy:finalize': sls invoke -f functionName &&
'remove:remove': npm run scriptName && sls invoke -f anotherFunctionName
Now, after successful deployment via serverless deploy
, sls invoke -f functionName
is triggered.
Similarly, on removal using serverless remove
, npm run scriptName && sls invoke -f anotherFunctionName
executes.
Complete list of Serverless framework's Lifecycle events / commands is available here - https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With