[英]How do I deploy Node.js code to run on an interval without exceeding free deployment tiers
I am trying to deploy a node application that will execute code periodically (I was hoping to execute once every 1-5 minutes).我正在尝试部署一个将定期执行代码的节点应用程序(我希望每 1-5 分钟执行一次)。 This code will make several API calls to different platforms and route some lightweight json data (mostly text and numbers).
此代码将对不同平台进行几次 API 调用,并路由一些轻量级 json 数据(主要是文本和数字)。
I was hoping to deploy this project using either Heroku, Amazon EC2, or Amazon Lambda and would like to stay within their free tiers and I am not sure how my code will interact with their servers.我希望使用 Heroku、Amazon EC2 或 Amazon Lambda 来部署这个项目,并希望留在他们的免费套餐内,我不确定我的代码将如何与他们的服务器交互。
If I deploy this code to run using a setTimeout, does this mean that I am requesting the servers to always be "on" and I will essentially be charged for 100% uptime?如果我部署此代码以使用 setTimeout 运行,这是否意味着我要求服务器始终处于“开启”状态,而我基本上需要为 100% 的正常运行时间付费? I could see this being an issue as Heroku only provides 550 free hours per month and Amazon EC2 provides 750 free hours per month.
我可以看到这是一个问题,因为 Heroku 每月仅提供 550 个免费小时,而 Amazon EC2 每月提供 750 个免费小时。
The code is pretty lightweight and should only be running momentarily so it would be a shame to have a server running 24/7 for only a few seconds of actual usage per day.该代码非常轻量级,应该只在短时间内运行,因此如果让服务器每天 24/7 天运行,而实际使用时间只有几秒钟,那将是一种耻辱。 How can I best deploy this code to run periodically?
我怎样才能最好地部署此代码以定期运行? Is there another service that I can use here?
我可以在这里使用其他服务吗?
Also, below is the barebones of what my code would look like.此外,下面是我的代码的基本结构。 Please let me know if there is something glaringly obvious that I am missing that could be an issue.
请让我知道是否有明显的我遗漏的东西可能是一个问题。
const axios = require('axios');
const asana = require('asana');
const { Dropbox } = require('dropbox');
function apiCallOne() {
...
}
function apiCallTwo() {
...
}
function runMyCode() {
apiCallOne();
apiCallTwo();
...
}
setTimeout(runMyCode, 1000);
With EC2 you will definitely get charged by uptime of the resource, whether you are using it or not.使用 EC2,您肯定会按资源的正常运行时间收费,无论您是否使用它。 Although 750 free hours p/month is basically 1 free tier instance p/month.
虽然每月 750 小时免费小时基本上是每月 1 个免费层实例。
Now I'd recommend Lambda as it seems a pretty simple code.现在我推荐 Lambda 因为它似乎是一个非常简单的代码。 And with Lambda you have 1M free requests per month and 400,000 GB-seconds of compute time per month.
使用 Lambda,您每月有 1M 的免费请求和 400,000 GB 秒的计算时间。 .
. But Lambda by itself can't run on schedules, you will need to use AWS CloudWatch Events for that.
但是 Lambda 本身无法按计划运行,您需要为此使用 AWS CloudWatch Events。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.