AWS EC2 Scheduling Tasks with Windows Scheduler - amazon-ec2

If I have a Amazon Redshift instance and an Amazon EC2 instance (running windows amongst other things), can I set up windows scheduled jobs in the EC2 instance that connects to Redshift and runs copy commands?
Really what I am asking is 'is EC2 just a VM on the cloud' and can I do anything I like in it (like set up windows scheduled jobs and be guaranteed they will run on a scheduled time)
It seems that AWS data pipeline is the recommended way to have scheduled jobs load data into Resdshift but this starts to get pricey with frequent jobs

I ran up a redshift instance and a EC2 windows 2012 instance
I installed the ODBC redshift driver
I ran a VBScript that incremented a counter in a table
I scheduled that script in task scheduler
I logged out of EC2 and came back and the data was updated.
So it seems that using windows scheduler on EC2 is a valid alternative to AWS data pipeline of you want to do it that way.
I haven't yet tried the copy command but I will come back and document that also if I have time

Related

Task from task scheduler does not start at start ec2 instance without login

I have scheduled EC2 instance to start every morning using Lambda. I have configured some task in task scheduler which I want it to run once EC2 is up however task wont get triggered until I login to EC2 instance. I want my task scheduler runs automatically at defined time without login to EC2 instance. Its a windows instance.
I tried configuring task without login but it doesn’t invoke.
Did you choose the Run whether user is logged on or not option of the task?
Fix Scheduled Task Won’t Run for .BAT File
Next, you have to choose the Run whether user is logged on or not option
To run a script every time an Amazon EC2 instance starts, simply add the script to this directory:
/var/lib/cloud/scripts/per-boot/
Most Amazon EC2 AMIs have cloud-init installed. It is responsible for running scripts from User Data. It will also check the above directory and run any scripts it finds there. This does not require a user to login.

ECS ec2 instance with user data

To launch docker-compose, I use AWS ECS.
When create cluster, ec2 instance automatically launched.
And can't launch with none instance. Must have at least 1 instance.
To time sync(https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html), I have to execute shell script before ec2 instance running.
I searched google few hours, there is no correct answer.
Is there any solution to launch cluster with user data?
Thanks.

Run batch file on windows ec2 instance then shutdown instance?

I have a .bat file on a windows ec2 instance I would like to run every day.
Is there any way to schedule the instance to run this file every day and then shut down the ec2 instance without manually going to the ec2 management console and launching the instance?
There are two requirements here:
Start the instance each day at a particular time (This is an assumption I made based on your desire to shutdown the instance each day, so something needs to turn it on)
Run the script and then shutdown
Option 1: Start & Stop
Amazon CloudWatch Events can perform a task on a given schedule, such as once-per-day. While it has many in-built capabilities, it cannot natively start an instance. Therefore, configure it to trigger an AWS Lambda function. The Lambda function can start the instance with a single API call.
When the instance starts up, use the normal Windows OS capabilities to run your desired program, eg: Automatically run program on Windows Server startup
When the program has finished running, it should issue a command to the Windows OS to shutdown Windows. The benefit of doing it this way (instead of trying to schedule a shutdown) is that the program will run to completion before any shutdown is activated. Just be sure to configure the EC2 instance to Stop on Shutdown (which is the default behaviour).
Option 2: Launch & Terminate
Instead of starting and stopping an instance, you could instead launch a new instance using an Amazon CloudWatch Events schedule.
Pass the desired PowerShell script to run in the instance's User Data. This script can install and run software.
When the script has finished, it should call the Windows OS command to shutdown Windows. However, this time configure Terminate on Shutdown so that the instance is terminated (deleted). This is fine because the above schedule will launch a new instance next time.
The benefit of this method is that the software configuration, and what should be run each time, can be fully configured via the User Data script, rather than having to start the instance, login, change the scripts, then shutdown. There is no need to keep an instance around just to be Stopped for most of the day.
Option 3: Rethink your plan and Go Serverless!
Instead of using an Amazon EC2 instance to run a script, investigate the ability to run an AWS Lambda function instead. The Lambda function might be able to do all the processing you desire, without having to launch/start/stop/terminate instances. It is also cheaper!
Some limitations might preclude this option (eg maximum 5 minutes run-time, limit of 500MB disk space) but it should be the first option you explore rather than starting/stopping an Amazon EC2 instance.

AWS EC2 - Cloudera Manager- Stopping instances

I have setup the hadoop cluster on Amazon EC2 using cloudera manager. Cloudera manager created two instances and all is working as expected. I am trying to stop the cloudera created instances through AWS console but there is no option to stop. We have only "Terminate" and "Reboot". I don't want to terminate these instances as i want to reuse these instances.
How to stop these instances ?
Since your instances came from an instance-store backed AMI you will only be able to reboot and terminate the instances. Look in the Management Console under "root device" to confirm this is the case.
To get around this, you can create an AMI from your instances then restart your environment using the new AMI which would give you the option to stop your instances.

Running a script on an AWS server

I have a script that I need to run once a day that requires a lot of memory. I would like to run it on a dedicated amazon box.
Is there some automated way to build a box, download all required software (like ruby) and then run my script. After the script is ran, I would like to shutdown the box.
The two options I can think of are:
I am thinking about hacking EMR to do this. (My script is a mapper against an empty directory)
Chef - This seemed like too much for one simple script.
You can accomplish setting up a new EC2 instance on startup using the official Ubuntu AMIs, the official Amazon Linux AMIs, and any other AMI that supports the concept of a user-data script.
Create a script (bash, Perl, Python,
whatever) that starts with #!
Pass this script as the user-data when running the EC2 instance.
The script will automatically be run as root on the first boot.
Here's the article where I introduced the concept of a user-data script:
Automate EC2 Instance Setup with user-data Scripts
http://alestic.com/2009/06/ec2-user-data-scripts
Your user-data script can install the required software, configure it, install your work script, and set up a cron job that runs the work script once a day.
ENHANCEMENT:
If the installation script don't take a long time to run (e.g., under an hour or few) then you don't even have to run a single dedicated instance 24 hours a day. You can instead use an approach that lets AWS start an instance for you on a regular schedule.
Here's an article I wrote that provides details on this approach with sample commands:
Running EC2 Instances on a Recurring Schedule with Auto Scaling
http://alestic.com/2011/11/ec2-schedule-instance
The general approach is to use Auto Scaling to start an instance with your user-data script on a regular schedule. Your job will terminate the instance when it has completed. They key is to suspend Auto Scaling's normal desire to re-start instances that terminate so that you don't pay for a running instance until the next time your job starts.

Resources