Gratis bloemen zaaien voor de bijen

Er is steeds minder ruimte voor bloeiende planten: Nederland wordt steeds voller gebouwd, veel tuinen zijn betegeld en onze landbouw is in een monocultuur veranderd. Een ware ramp voor de bijen. En…


独家优惠奖金 100% 高达 1 BTC + 180 免费旋转

How to schedule your instances on AWS?

The service costs on AWS can very easily go out of hand if not monitored correctly. With the EC2 pricing varying from as low as $0.02 per hour to $5.52 per hour, it is always a good practice to ensure that your development EC2 servers are stopped when no one is using them.

Though there are cloudformation templates available, we can very easily set up a scheduler using Cloudwatch and Lambda. I use Lambda on Node JS but you can switch to Python or Java as per your convenience.

Create a policy named “ec2-start-stop-policy” with the following permissions:

Then create a role called “ec2-start-stop-role” and attach this policy to the role

2. Create two lambda functions for stopping and starting your instances

Create a lambda function “ec2-instance-start”.

From the options, choose “Author From Scratch”

Choose the runtime “Node.js 10x” from the drop down.

In the Permissions tab, expand the Choose or create an execution role.

In the execution role, choose “Use an existing role”

In the existing role, choose “ec2-start-stop-role”

Then create the function, and add the following code to the function

In the Environment variables tab of the lambda function, add “instanceList” to the key and instance ids of your ec2 instances separated by a comma(,).

Repeat the same process once more. This time name the function “ec2-instance-stop” and in the code, change line 10 to

Dont forget to add the environment variable in the function.

3. Create the Cloudwatch rule to schedule

Create a rule called “StartEC2Server”

Choose “Schedule”

Now you can choose between fixed rate and cron expression. Choosing fixed rate is easier but cron expression gives you the fine control of setting the schedule for the exact start and stop time.

If you want to schedule your server to start everyday at 11:00PM UTC everyday. Enter the following cron expression:

In the Targets section, click on Add Target

From the drop down choose Lambda function and in the function choose “ec2-instance-start”.

Click on Configure Details and your rule is now created.

Repeat the same steps for “StopEC2Server” rule and add the lambda function “ec2-instance-stop”.

Now, you have successfully scheduled your instances. Remember to configure the startup script on the server. On t2.micro instances and Linux AMI, the script is in /etc/rc.d/rc.local

Also, if you are using an instance that does not has a VPC configured, then the public IP will change on restart. This can be taken care of by using Elastic IPs.

Add a comment

Related posts:

The Invisible Threat to Some Medical Devices Could Be Deadly

Big brother is here and so are the dangers that come with such technological oversight. Just this month, the FDA was forced to recall all Medtronic insulin pump devices after learning of…

ClickaCRM Review

Customer Relationship management; what is it? And why do you need to choose ClickaCRM for your customer relationship management? In this ClickaCRM review, we are going to look at some of the…

Sales advice. How your personality makes a difference when closing a deal.

our last post was about “closing deals even when your client has a better offer from a competitor”. An important point that we mentioned was: “Making business is about trust. If you are an honest and…