Powerful AWS Bot for automation using Telegram Bot API written in PowerShell

Sometimes back I was working on a free notification system using Telegram Bot (https://telegram.org/blog/bot-revolution), and I wrote a simple function in PowerShell, which could be use in various ways for sending instant notification to any smartphone for free (http://bit.ly/2ys1gF5).

I thought what else we could do with it, and I have got an idea to use it as AWS Automation Bot to perform simple tasks. I have created a set of instructions for a Bot using PowerShell script which we could use to perform the following tasks instantly instead of doing it from AWS console.

  1. Getting instance details using instance name.
  2. Getting attached volume details using instance name.
  3. Getting list of the available snapshots for a instances using instance name.
  4. Getting the console screenshot for troubleshooting using instance name.
  5. Getting the console log for troubleshooting using instance name.
  6. Start an instance using instance name.
  7. Stop an instance using instance name.
  8. Restart an instance using instance name.

Continue reading

Add new Admin Account to AWS Windows Instances to rescue the system

As mentioned earlier, we could reset the local admin password of windows instances via registry, but unfortunately that will not going to help us if we forget the user id details or we renamed the user id. And the good news is, we still will be able to logon into the system by creating one new Admin Account using AWS User Data. This process is very simple as described bellow.

  • You have to re-attached the root volume of faulty system to a working AWS instances.
  • Now, you have to use EC2Rescue to enable user data (Ec2HandelUserData), which will execute a script on next boot. (*This could be done by editing config.xml file of EC2Config)

  • Once done, you have to re-attach the volume to the original system as root (/dev/sda1) volume.
  • Now, from AWS EC2 Console, you have to select the server and edit the User Data before starting the server and add the following PowerShell script. This script will create a Admin Account called “MyAdminX” with the password “!!4SJKAHGYWMd4!!” on first boot and you will be able to logon to the server using this new account.

 


I hope this will be helpful for you.

How to use AWS PowerShell cmdlets with Filter

I personally can’t imagine supporting a big infrastructure without introducing automation and to automate something you have to use command line. If you are more into Windows and started working on AWS for your clients, then I assume that you would love to start managing AWS using AWS PowerShell Module like I do. AWS Console is really good and informative but when it comes to bulk activity I am always depending on PowerShell.

There is a very good documentation created by Amazon for AWS PowerShell, you will get the basic help for all the available PowerShell cmdlet from here. It will be very much helpful for you to start working on AWS PowerShell, but unfortunately when it comes to using filter available for those cmdlet, you won’t be able to find any good example. Using filter on a AWS cmdlet will be a smart move and it also reduce the total execution time. Initially I also struggled to get this working due to lack of examples, but later I figured it out, and now I always try to utilize filter and I am writing this to you help you understand how easily we could use this.

Some of the sample, hope this will help you.

Extract the list of the snapshots under your ownership.


This script, I am using filter to identify the snapshots mapping with instance

Continue reading