简体   繁体   English

如何部署 Node.js 代码以在不超过免费部署层的情况下按时间间隔运行

[英]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.

相关问题 使用capistrano部署Node.js项目时,如何成功通知Airbrake部署? - How do I successfully notify Airbrake of a deployment when using capistrano to deploy a Node.js project? 如何在 Wordpress 插件中运行 Node.js 代码? - How do I run Node.js code in a Wordpress plugin? Windows的node.js和Cygein,如何运行代码? - node.js and Cygein for windows, how do I run code? 在一定时间间隔后如何运行Node.js api? - How do I run Node.js api after certain interval of time? 如何将node.js应用程序部署到服务器? - How do I deploy my node.js app to a server? 如何在没有测试的情况下为某些 Node.JS 代码生成代码覆盖率? - How do I generate code coverage for some Node.JS code without tests? 如何在不超过用户速率限制的情况下使用node.js向Google Drive API发出3千个请求? - How can I make 3 thousand requests to Google Drive API using node.js without exceeding User Rate Limit? 如何在没有管理员权限窗口的情况下运行 node.js? - How do I run node.js without admin privileges windows? 如何在不使用Ajax /使用express的情况下从html页面运行node.js函数? - How do I run a node.js function from an html page without using ajax/using express? 如何在客户端服务器上运行我的 node.js 应用程序而不与他们共享代码库? - How do I run my node.js application on a client's server without sharing the codebase with them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM