I want to develop a small application and thought of using DO serverless functions.
The function is very small and will be activated by an HTTP request, about once a month. Therefore I think creating a full App for will be an overkill…
What I need to achieve:
Will DO serverless functions be up to the task? Or do I still need to lunch a full App + Express for this?
Can I requier NPM pachages? Can I connect to the MySQL DB? Can I connect the MySQL DB using DO native connector like with the Apps or do I still needs to use some NPM package like sequelize.js?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Click below to sign up and get $200 of credit to try our products over 60 days!
This comment has been deleted
You should be able to accomplish this with DO Functions. It sounds like you will need to accomplish two main things.
As you note, you can implement this using a single function or a function per use case. The idiomatic approach with FaaS is to use a function for each use case.
For use case #1, we have an example repo showing how to connect to MySQL. You’ll notice that it uses a
package.jsonfile to specify NPM dependencies to use, like for the MySQL library. For more info on dependencies in Node.js functions, see our docs.
For use case #2, we don’t have an example showing how to use the WordPress API, but you could use our existing examples to build this function. You may be able to find SDK libraries for this API on NPM. If not, you’d use your preferred HTTP library to make these requests yourself.
Concerning networking best practices, because we don’t yet support VPC connections between droplets, App Platform, and Functions, you’ll want to secure your connections between these products using other techniques, like Trusted Sources and WordPress API credentials. That way, when your functions connect to MySQL and to the WordPress API, they do so as securely as possible since the traffic would be traversing the public. For the same reason, ensure you’re using HTTPS instead of HTTP for this traffic.