I know they now charge per min, how can I automate once every 50mins I open an instance for a few mins, up to 5mins lets say of EC2, and then it computes my scripts, then closes and repeat.
This sounds like a use case for Lambda. If you can get your script to work entirely within the Lambda framework, you’ll find it’s extremely inexpensive.
Otherwise, you can still trigger Lambda with a scheduled event (cron) and have a simple script launch your EC2 instance when it’s time. Make your script run at boot, and when it finishes, have it shut down the instance.
I am novice as well and got 3 services tied together with Lambda working in a few hours.
My use case was deploying a SageMaker endpoint which is required to be called from a Lambda function for security. The Lambda outputs JSON and then I exposed the Lambda function to web request with API Gateway.
During my implementation of this I discovered nothing but comments of peoples minds blown at how powerful Lambda could be for replacing various infrastructure including even hosting an entire web app.
yea and if needed i can strip the function down. on my 50mb line my functions can be done in 1min with 350mb of ram. I could try make them more efficient
Don’t worry about memory too much as the Lambda performance (CPU and network) is tied to the memory limit you choose on the function. Running once per hour even at a full 5 minutes with 1024mb memory should still be extremely cheap.
There are a lot of tools to make it easier or more efficient to setup/test/use Lambda functions, and I’ve personally used this one (mainly for quick local testing): https://github.com/nficano/python-lambda
it’s a bot for a text based video game from 2006. it’s an assignment basically.
it uses beautifulsoup, robobrowser, re.
it goes on a site, logs in, goes to a bunch of pages, parses the html, reads it with beautiful soup then a bunch of loops and if statements decide what actions to take.
so it takes around 30 seconds per action on my 50MiB/s internet with 350mb of ram.
there are 2 actions is needs to complete every 50mins.
if you would like to see my code I can send snippets later.