Code-Test-Code cycle in Amazon Cloud (AWS) - javascript

I new to Amazon AWS and want to create a cloud-based REST API in Node.js.
Usually I develop the program along with testing it. It means I write some tests, and then write the code that makes those tests run successfully. So in a typical programming session, I may run the tests or the app tens of times.
When I do this locally it is easy and quick. But what if I want to do the whole process on Amazon cloud? How does this code-test-code cycle look like? Should I upload my code to AWS every time I make a change? And then run it against some server address?
I read somewhere in the documentation that when I run a task for a few minutes (for example 15min), Amazon rounds it up to 1hour. So if in a typical development session I run my program 100 times in an hour, do I end up paying for 100 hours? If yes, then what will be the solution to avoid these huge costs?

When I do this locally it is easy and quick.
You can continue to do so. Deploying in the cloud is does not require developing in the cloud.
But what if I want to do the whole process on Amazon cloud?
When I do this, usually edit the code locally, the rsync my git directory up to the server and restart the service. It's super-quick.
Most people develop locally, and occasionally test on a real AWS server to make sure they haven't broken any assumptions (i.e. forgot something at boot/install time).
There are tools like Vagrant that can help you keep your server installation separate from your development environment.
As you grow (and you've got more money), you'll want to spin up staging/QA servers. These don't have to be run all the time, just when changes happen. (i.e. have Jenkins spin them up.) But it's not worth automating everything from the start. Make sure you're building the right thing (what people want) before you build it right (full automation, etc.)
So if in a typical development session I run my program 100 times in an hour, do I end up paying for 100 hours?
Only if you launch a new instance every time. Generally, you want to continue to edit-upload-run on the same server until it works, then occasionally kill and relaunch that server to make sure that you haven't screwed up the boot process.

Related

Host Python on server and call from React Expo App

I am working on an app that uses machine learning, and recently run into a problem. I found out that Expo and Python do not really work together.
I thought that a solution would be to host and run my machine learning model (Python) on a server, and then make requests from my JS Expo app, and I thought this would also have the hidden bonus of faster processing compared to just on my laptop.
So, can people confirm whether firstly this is possible (to call python code running on a server, from a JS Expo app) and if so, then provide some recommendations as to where I can host this?
This is for a university project, so I am hoping to find something either free or cheap, thanks.
I thought this would also have the hidden bonus of faster processing compared to just on my laptop.
If you want to do it for free then lowest tier instances on any cloud will have 1 or 2 cores plus 1-2 GB of RAM, it won't be stronger than your local device and it won't have any hardware acceleration, but if you planned to run that on your phone then it might be enough
So, can people confirm whether firstly this is possible (to call python code running on a server, from a JS Expo app)
Short answer yes, but
The way you formulated this question does suggest that you don't know how this communication would work. You would need to
send http request from expo app to some endpoint on your server
implement server code that could accept that request, in your case it's probably best to do that in python(with sth like django or flask)
in your server code execute tensorflow code
if tensorflow code executes quickly you can send results in the response if not you will need to have second endpoint to check results
This is for a university project, so I am hoping to find something either free or cheap, thanks.
for local development you will need to host it locally either way, for university project it should be enough, but if you want to have it on public server you can get free tier or some starting credits on almost any cloud service e.g. digital ocean gives 100$ credit for students
Alternatively you can use tensorflow in react-native app, you just can't do it in python, https://blog.tensorflow.org/2020/02/tensorflowjs-for-react-native-is-here.html?m=1

How to make a GET request to http:localhost from word javascript api?

I am trying to develop a word addin. It will provide corrections for a word based on the context. The language will be Bengali.
My idea is that there will be a python server in localhost. Yes it will run on the localhost. Otherwise if it is a central server there will be too much requests. So somehow (maybe through an exe file I will run the server on in localhost) I will make the server run on localhost. The .exe file can be distributed to anyone and when he/she runs it, it will run on their localhost and then he/she can use the word addin (that I am developing) to call to the localhost to get the desired output. It should be noted that, the platform will be windows.
But the problem is word JavaScript api doesn't let me call to the localhost in http. It only can call to https. But localhost isn't https. If there's anyway I can call the word api in http localhost? Also, as I am looking to make a complete product, I am trying to skip OS related configurations. For example, making localhost certified. Because, when the application (python server) will be transferred, I don''t know how and if it is possible to run script in others' windows OS and make their localhost certified. So, it will be very helpful to make word api just call to my localhost using http (or atmost https://localhost) and not some https://somedomainname.com.
For coding environment to develop the word addin, I am using script lab. So, it will be better to find a solution that will be supported by script lab.
There are a few problems with this approach.
For one - you will never pass the validation, when you're trying to call the localhost - since it will fail by default and you'll be asking the users to install an additional software to support your JS add-in. The add-ins should work standalone.
If there's anyway I can call the word api in http localhost?
No - there isn't in this context. Your final manifest URL's need to be https and they should be externally available.
I am trying to skip OS related configurations. For example, making
localhost certified. Because, when the application (python server)
will be transferred, I don''t know how and if it is possible to run
script in others' windows OS and make their localhost certified.
One of the benefits of the Office store is that Microsoft can look after if the add-in the customers are installing (which we're developing) is malicious or not. Trying to say you want to bypass validation doesn't help this case.
My idea is that there will be a python server in localhost. Yes it
will run on the localhost. Otherwise if it is a central server there
will be too much requests.
It should be a central server and you should handle the scalability aspect of it. You might not have a huge number of users as you're imagining to begin with. I'd recommend Heroku - they support python and their first tier is free, you can develop & publish your add-in and once it starts getting significant traffic, you can look into moving it to other places.

Possible to bypass Heroku's free plan's "Sleeps after 30 mins of inactivity" with console.logs?

Heroku has a free plan, as outlined here: https://www.heroku.com/pricing
One of the drawbacks of the free plan is that the server goes to sleep after 30 minutes of inactivity. Is it possible to bypass this if I have a console.log("stay awake"); occur every 20 minutes?
It is not possible to bypass that limit - in a sense that all your services will likely get shut down before the end of the month for much longer than 30 minutes if you do that all the time - but you can keep your process alive e.g. by hitting some endpoint periodically but you will quickly exhaust your free hours that way:
Verified accounts come with a monthly pool of 1000 Free dyno hours; unverified accounts receive 550. When a Free dyno is active, it draws from the pool; your free apps can run as long as there are dyno hours left in your monthly pool.
It may be useful if you need to make sure that you API is responsive for short periods of time like during a demo or a presentation.
Whatever you do make sure that it is not against the TOC. When in doubt ask the customer service. They are very helpful.
If you want an uninterrupted service but Heroku is too expensive then you should probably use a VPS like Digital Ocean or Vultr. They are much cheaper, work 24/7 and you can have few months for free with promo links (Digital Ocean, Vultr) but the drawback is that you will have to make more things yourself - like install Node, deploy the application, keep the OS, Node and all services updated and configured properly etc. It's not that hard to do but you need to know what you're doing and no one will fix your system for you. To see how to install Node on a VPS see:
NodeJS API with external deps in other language
Run npm as superuser, it isn't a good idea?
NPM and NODE command not found when using NVM
How to host website in NodeJS and MongoDB? And what will be the cost?
Simple node.js app deployment on DigitalOcean from GitHub
Install Node.js with downloaded binary on Ubuntu Desktop.. Where do the files go?

The "right way" to host multiple NodeJS domains on a single server?

I have a VPS that runs Apache and serves a number of WordPress site. I also managed to get a NodeJS server running on this same VPS account using the MEAN stack. Things worked fine with this setup.
I decided to add a second NodeJS/MEAN app to this same server, running on a separate port, and everything is operating fine - except I've noticed a significant impact to page load performance across all sites once I got this third server running.
I found this question and this question here on SO, but neither of these address performance. So my question is:
Is it possible/practical run two separate/unique domains on the same NodeJS server app? Or is that going to create more problems than it solves? (Note: I don't mean the same machine, I mean the same NodeJS instance)
If not, How can I improve performance? Is upgrading my VPS the only option?
So you can indeed run multiple apps on the same port/process. This can be done using the express-vhost module if you need to separate by domain. You can also use the cluster module to run a pool of processes that share resources (though they end up being the same 'app', you could combine that with the vhost approach to have a pool of processes service a number of domains.
That said, I don't think you're actually going to get the results you want. The overhead of a nodejs process is pretty trivial compared to most (e.g a JVM); the costs come mostly in whatever your custom code is doing. I think what's more likely happening is that whatever size server you've chosen for your VPS is just not enough to run everything you're throwing at it, or the node apps you've written are hogging the event loop through long running processes. It could also be the case that Apache is the hog; you'll need to do more diagnostics to get to the root of it.

Xampp + Php Websocket Maximum execution time error

its my firsttime using it.Ok i tried to use websocket ext. but i dont understand it :/
In this article http://www.sanwebe.com/2013/05/chat-using-websocket-php-socket/ i download it, extract it in folder, and i open command prompt execute this
c:\xampp\php\php-cgi.exe -q c:\inetpub\wwwroot\CC2\ws\server.php
I open index.php in 2 browser and connect it. Two browser connected as well. But after 30 second, connection is lost. I looked in cmd, gived this error
C:\Users\traBolic>c:\xampp\php\php-cgi.exe -q C:\inetpub\wwwroot\CC2\ws\server.php
<br />
<b>Fatal error</b>: Maximum execution time of 30 seconds exceeded in <b>C:\inetpub\wwwroot\CC2\ws\server.php</b> on line <b>28</b><br />
I dont understand it, is that normal? How can i keep connection live in a long time?
If you're already familiar with PHP and you don't want to move to an entirely new platform (node.js/socket.io), you CAN implement websockets with PHP.
Take a look at the Thruway project, which is a PHP implementation of WAMP (Web Application Messaging Protocol). It simplifies getting websockets working with PHP and provides SubPub and RPC.
I'm one of the developers of Thruway, so if you have any questions or need help getting something working, you can open an issue on github.
If you want to read more about WAMP, here's a good place to get started.
Also, php-cgi is designed to be run by your web server. Check and see if XAMPP has a php-cli.exe or a plain old php.exe and use that instead.
You need to set per
<?php set_time_limit ( 0 ); ?>
the maximum execution time of a php to infinite, because php has a default maximum execution time of 30 seconds.
You should have a look on Socket.IO which handles Websockets much better than php.
Best regards
Dustin
Edit:
ohh... sorry for not explaining socket.io...
Socket.IO is an module for nodejs:
Node.JS is the V8 Javascript Engine from Google Chrome for a server. So you can run a server with javascript on command line.
Socket.io is as I said a node module. In node JS you can import modules from npm which is an packet manager for node.JS. It provides functionality for bi-directional connections between the client and the server via websockets and fallbacks to long-polling xhr requests. Easiest way to come up with it is just trying it. For example you can try to start this chat app: Chat.
First you need to install node.JS, which should be simple node.JS.
You can start a node.JS server the same way you have already done it with php:
Console:
>node index.js
Now you should be able to use the chat by opening the index.html file.
To answer your question: No, you can not start socket.io with php. And you can neither use xampp to start a nodejs app.
There are a lot of tutorials in the internet right now. Someone has already created a list: Tutorials
Best
Dustin

Categories

Resources