AWS EC2 Spot Instance Cloudformation Template

I keep getting really irritated with myself. I write cloudformation for an EC2 instance, start the instance for a bit before terminating it, and then loose the cloudformation. To remedy this I recently spent a bit of time on a template, and uploaded it to github, like a smart person 🙂

/github.com/megah3rtz/aws_ec2_instance

There are 2 templates. “single_instance_basic” just launches an EC2 instance with no post config, whereas “single_instance_ansible” will install Ansible, and run a playbook in an s3 bucket defined in the cloudformation parameters.

single_instance_basic is a pretty simple template, but gives you a decent bit of power to get going, and enables you to do things like create multiple instances with the same configuration, and use your own AMI’s.

To run the cloudformation template, either log into the AWS console, and go to Services > Cloudformation > Create stack, and select upload template, or use the aws cli.

Parameters in the template have default values set, but the majority of these can be over-ridden.

If you use the AWS CLI and want to change some of the parameters, use the following command to get you started :

aws cloudformation create-stack --stack-name MYSTACK --template-body file:/single_instance.yml --parameters ParameterKey=ImageId,ParameterValue=ami-00011122

As a side note. The template uses spot instances. These use spot pricing, and in the majority of cases can save you 80% of the price of an on-demand instance.

Installing KODI (Krypton) on raspberry PI ZeroW with Linux

So for a first post, I’ll start off easily. I recently had an issue with the Raspberry PI 2 I use as a media center for the house. It would only show a black screen with no output. This turned out to just be a dodgy microSD card, as proven by swapping with a known good one. I’ll admit I had originally thought the board was dead, it isnt treated all that kindly and just hangs behind our TV via the HDMI cable. Seeing as I already had a Pi Zero floating about I decided to replace it with that, and use the Raspberry Pi 2 for another project.

I know this kind of instructional is already all over the place, but to be honest I wanted to get started with something nice and easy on the site, and all those YOUR ISP IS TRACKING ALL YOUR CLICKS, GET OUR VPN NOW!!!! adverts all over the pages. I will do a how-to on setting up a vpn on AWS Web Services that you can use for as many devices as you like for a few £/$ a month, and link it here but its up to you if you use it, i’m not going to try forcing it on you!

 

1 ) Ok, so to start get a raspberry pi zero W (The W is 100% worth it, just for the built in wifi) and a MicroSD card. 4GB is big enough, and if you can, make it a class 10 also. You will need power (any microusb power-supply should do the job) and a mini HDMI to HDMI adapter. All of these should be easily available from your local Pi supplier, or ebay.

Raspberry Pi Zero W

2 ) Now go get yourself a Linux distro that includes Kodi. Personally I use OSMC as it runs pretty well and I have had hardly any issues. For the pi Zero W you need to go to the link at the bottom of the download page for “Disk Images”, then select the latest release for “Raspberry Pi 1 / Zero / Zero W”

3) Once your file has downloaded, you need to un-compress it :

~# gunzip OSMC_TGT_rbp1_20180609.img.gz

This will only take a few moments, on even the most geriatric of systems, and you will then be left with the un-compressed .img file.

4) Check which device to write the image to. To do this I suggest the following. Use the command before inserting and a few moments after inserting your microSD card. Below is the output for me when I ran this.

Before

~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 59.6G 0 disk
├─sda1 8:1 0 54.8G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 4.9G 0 part [SWAP]

After

~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 59.6G 0 disk
├─sda1 8:1 0 54.8G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 4.9G 0 part [SWAP]
sdb 8:16 1 3.7G 0 disk
├─sdb1 8:17 1 512M 0 part
└─sdb2 8:18 1 3.2G 0 part

From this I can see that the device “sdb” has appeared after plugging in my microSD card. Depending on the adapter / connector you use, this may also appear as “mmcblk*” where * is likely to be 0 or another number.

5) Now you need to write the file to the microSD card. We are not copying the file onto the disk the way you would if you are copying photos on to a USB stick, here are are copying the .img file byte for byte to the microSD card.

WARNING!!! IF YOU ADD THE WRONG DEVICE AT THE END, YOU CAN WIPE A DECENT BIT OF YOU OPERATING SYSTEM AND MAKE YOUR PC UNBOOTABLE.

PLEASE RUN THE LSBLK STEPS ABOVE AS MANYTIMES AS NECESSARY TO BE CONFIDENT WHICH DEVICE YOU NEED TO WRITE TO.

first make sure none of the existing partitions are mounted.

~# umount /dev/sdb

then write the image to the microSD

~# dd if=OSMC_TGT_rbp1_20180609.img of=/dev/sdb

This can take a few minutes to complete, depending on the speed of the microSD card.

6) Enjoy! You now have OSMC & Kodi installed on the microSD card, and can insert this into your PI Zero and boot it up!

All being well after, resizing the filesystem etc, you will be greeted by the following screen.

Splash screen for OSMC with kodi installed
OSMC splash screen with Kodi installed

 

 

 

903-899-0906