AWS EC2 instance scheduler easily - amazon-ec2

I'm using ec2 for development, and it's a waste of money after work. How much time does it take to create a scheduler that automatically starts every morning at 8 am and ends at 7 pm?
I've read the guide provided by AWS, but it's a little difficult.
https://aws.amazon.com/ko/answers/infrastructure-management/ec2-scheduler/

You can easily make your own scheduler using Amazon CloudWatch Events to trigger an AWS Lambda function on a regular schedule.
Amazon CloudWatch Events has the ability to schedule events, such as triggering a Lambda function
A Lambda function can do whatever you wish, such as starting/stopping instances based on a tag
See: Creating an Enterprise Scheduler Using AWS Lambda and Tagging

It is also good to make your own guide based, it takes about a week.
Assuming a developer costs around $ 200 per day for a developer, it will take at least $ 1000 for five days of development.
The CloudScheduler service is $ 10 per month, and if you have $ 1000, you can use the service for 100 months, about 4 years.
https://scheduler.gncloud.io/
Service is cheaper than development. Just use the service.

Though its difficult to implement to scratch, you can use ec2-scheduler.template to deploy the CloudFormation stack to provision the required platform to schedule.
This approach is more convenient than implementing it from scratch using a scheduled Lambda function and EC2 SDK.

Zero. AWS just release something that does this for free: https://aws.amazon.com/answers/infrastructure-management/instance-scheduler/
This is a Lambda function that runs regularly and looks for tagged resources to power down. The weaknesses are it is pretty low level and you have to make one fixed schedule for your entire team. But is is free.
Disclosure: I work with PowerDown that offers a product that goes quite a bit further and will also handle AutoScale groups and Fargate containers -- and it will create the schedule for you based on user needs. Here is my write up about it: https://www.powerdown.io/blog/posts/2018/announcing-powerdown.html

Related

I got some architecture questions

Warning : I'm new in application architecture and officially speaking - this is the first time I'm designing something this big. This is also my own application so I got full authority to change things.
I'm building a serverless application which consists of an on-demand application streaming platform.
Customers who seek to try a specific application (usually large and expensive ones like Photoshop or Solidworks for example) could have the possibility to directly try one from their computers, on their browser, while the application is running on a similar to their computer type of infrastructure.
I'd use the CI/CD pipelines and IaC technology to build EC2 infrastructure that will host these applications and use those same technologies to destroy that infrastructure, since it's volatile.
So to create/destroy that EC2 infrastructure I use the GitLab API.
I've thus decided to go with AWS Lambda & GitLab for now.
Now the architecture questions :
Is it better to have one serverless function that handles everything or several functions ?
I'm planning to destroy the EC2 infrastructure after a certain amount of time (10-15 minutes). How should I schedule HTTP communication? Should I use a queue like SQS? Should I use some database and check every minute?
Again, thanks a lot for your wisdom!
Edit : Clarification on some stuff.

Which t3 EC2 instance should i pick as a start when launching a spring/angular webapplication?

I have built a spring boot/angular web application that uses a mySQL database for storage. The web application's main purpose is to be like a social media website for gardeners. Next to this it has a couple of tools that allow the user to generate a personalized planting calendar based on the monthly average temperature curve of the region where the user lives. Alternatively the user can also generate a personalized planting calendar based on planting journals made by other users that live within a certain radius near the user doing the calendar generating. I am using Hibernate Search for this.
I do not expect to get millions of visits in the first months after launching the web application, so my question is: What would be the best ec2 instance type to start out with? Could a t3.micro support an application like that for the first months or two? Also, How will i know when the current instance type can no longer handle the incoming traffic without lag and therefore i need to upgrade to a bigger instance like t3.medium or large?
Thank you
If the instance is suitable or not depends on many things. Based on my experience a micro instance is not enough for many use cases.
My suggestion is to start with a t3.small instance, start gathering metrics in CloudWatch to establish your baseline for few days. Then decide if it is enough or not.
If you are filling all your resources you can eventually upgrade to a bigger instance. However if your app is dealing with Java I think that a medium size is the minimum start.
About the lag and other things, first suggestion is to put CloudFront on top of the EC2 at least for all your static content (suggestion: put your static contents on S3 don't let EC2 serve them). Then I think that the only option is to rely on some third party performance tool, external to AWS.
By the way, I have built the same app on iOS many years ago, with a support website hosted on AWS. Now the app is gone, and the website is unmaintained :-)

What is the best practice to manage EC2 instance up/down/hibernate scheduler?

We have 2 - 3 EC2 c5.9xlarge instances for research.
Besides the option to shut them down on a particular hour according to a scheduler please advise what is the best way to keep them up and running when I "touch" them by connecting/clicking them or any other wake up policy?
My goal is to save expenses and I am trying to find a best practice to manage these instances wisely.
Please advise from your professional experience.
You can utilize the EC2 Hibernation feature via which you can pause/resume your instances. This would give you the convenience of resuming your instances with all the processes running just like the way you had left the instance saving you a lot of time and effort in setting up the environment and reach your productive state faster.
Currently, EC2 Hibernation is available for Amazon Linux 2, Amazon Linux and Ubuntu 18.04. It is supported for your instance type which you use.
More details can be viewed here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html
If you have Jenkins or other CI/CD tool available you can create a job there that would enable/disable particular EC2 instances. If you want something smaller then you can use aws-cli with cron and do the same. Some of my customers turn their VMs on at 7 AM and turn them off at 7 PM (mostly for testing/staging environments).

How to setup Amazon Lambda with micro services in Node.js

I am looking forward to work in a Amazon Lambda with Node.js
They call it server less, So is it a better way to host our code then traditional hosting servers ?
I am open for the suggestions, thanks in advance!!
It is called serverless as you dont manage and maintain the underlying server and the runtime.
Basically you write your code in one of the supported languages, say node.js, and then configure events that will trigger your code.
Example in case of AWS, the events can be a API GW call, a SQS message, a SNS notification etc.
So it can be better depending on what you are planning on doing.
Do note that there are certain limits that AWS imposes by default on accounts for AWS Lambda.
Also there can be slight startup penalty for a Lambda.
A plus point of Lambda vs Hosting your code in EC2 is that with Lambda you dont get charged if your code is not used/triggered.
However, do note that for functions that have heavy usage it might be better to
host your own EC2.
Most important a Lambda has to be stateless.
Considering all the above factors you can take a call on whether AWS Lambda and Serverless Architecture fits your needs.

AWS EC2 pay per hour with 100% availability

I want to run an server for an application I have.
I'm a complete beginner with AWS, so bear with me.
There will be about 50 users (all from the same time zone) that will be accessing the server and I would like to have near 100% availability.
The application I have requires 2 processors and 2GB ram.
I could pay for a machine 24/7 or even only 18 hours a day, assuming I turn it off at night, but I there will be some days where the server is not used at all.
I was wondering if the following is possible: when amazon detects that someone is requesting something from my server, it turns it on in real time, and then forwards the request to my server. After say 5 minutes of no activity, it will turn my server off. This way I can only pay for hours when there is traffic.
Is this possible?
How have people solved similar problems?
No this isn't possible. There is nothing built into AWS to detect traffic and start an EC2 server like you suggest. Plus the startup time on an EC2 server is at least a couple minutes, so those first incoming requests would have to wait a really long time.
You might want to look into running multiple small servers instead of a single larger server. AWS does have the ability to balance the load across multiple servers and add/remove servers from the pool based on traffic. You could have as few as one server running when there is no traffic, and have more servers automatically created as load increases. Look into the AWS Elastic Beanstalk service for this.
If you want to run a truly "serverless" environment where you only pay for compute cycles in milliseconds, instead of servers by the hour, you could look into using AWS Lambda. If you can architect your system to run on Lambda you are almost guaranteed to save costs, but it can be a real challenge to convert an existing system to this sort of architecture.
If you want to look outside AWS you might find something more along the lines of what you describe with Google App Engine. Heroku's free tier also works similarly to your description, but as soon as you outgrow the free tier you have to upgrade to always-running instances.

Resources