Quick & easy AMI generator

I have been meaning to put together a Lambda function to create an AMI from a custom EC2 instance.  It’s a pretty typical scenario, but I haven’t taken the time to roll my own. Recently, I ran across an article on StackOverflow which provides a CloudFormation template that:

  • constructs an EC2 image,
  • creates a Lambda execution role for AMI building,
  • creates a Lambda function for constructing an AMI, and
  • uses a custom resource to make an AMI from the instance via the Lambda function.

The Lambda function is written in the JavaScript SDK (node.js), is short and sweet, and easy to modify.

So, I modified both the template and Lambda function to make it a little more generic and reusable. Also, I fixed a logic error in a the original Lambda.  Finally, I wanted to customize the name of both the image and AMI, so I created an InstanceName parameter. The only other parameter for the CF template is InstanceType, which I defaulted to t2.micro. Add your desired instance types to the list in that parameter’s AllowedValues attribute. The base AMI for the instance is a region-specific Amazon Linux image. Once the stack is deployed, simply update the template with your userdata changes to create new custom AMI’s. It’s a very helpful tool to have in your CloudFormation toolbox.

The template is available from my aws-mojo repo on GitHub in both JSON and YAML formats.

Enjoy!

cfn-flip – CloudFormation format flipper

In a previous post, I talked about how CloudFormation now supports YAML for templates. The fine folks at AWS Labs have since released a Python package, cfn-flip, that you can install and use from a shell to convert a CF template from one format to the other: if you feed it JSON, it converts to YAML, and vice-versa.  It also works when used as a Python library.

Installing and using cfn-flip is this easy:

[rcrelia@seamus ~]$ pip install cfn-flip
Collecting cfn-flip
 Downloading cfn_flip-0.2.1.tar.gz
Requirement already satisfied: PyYAML in /usr/local/lib/python2.7/site-packages (from cfn-flip)
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from cfn-flip)
Building wheels for collected packages: cfn-flip
 Running setup.py bdist_wheel for cfn-flip ... done
 Stored in directory: /Users/rcrelia/Library/Caches/pip/wheels/1b/dd/d0/184e11860f8712a4a574980e129bd7cce2e6720b1c4386d633
Successfully built cfn-flip
Installing collected packages: cfn-flip
Successfully installed cfn-flip-0.2.1

[rcrelia@seamus ~]$ cat /tmp/foo.json | cfn-flip > /tmp/foo.yaml

 

CloudFormation Templates in Atom

I’ve posted before about my absolute love of Atom.  I recently was doing a lot of CloudFormation work and just started using atom-cform, a CloudFormation syntax completion plugin for Atom written by Diego Magalhães. It works great and is a port of the popular CForm package in Sublime Text, which I have missed since jumping ship from Sublime to Atom a little over a year ago. It provides real-time context-sensitive CF template scaffolding for everything from parameters to resources:

atom-cform

Another super-helpful CloudFormation plugin for Atom that does both CloudFormation stack validation and launching is Cory Forsythe’s atom-cfn. You have to have a working AWS configuration (the author recommends a working awscli install which is what I have) in place for both validation and launching as it hits the API in AWS. Simply bring up the command palette in Atom (Shift-Cmd-P on macOS) and select either “Cloudformation: Validate” or “Cloudformation:Launch Stack”. Key-bind those commands for added efficiency.

Ad-free Browsing on iOS

This is not a typical post since it is not DevOps-related, but I wanted to share my recent experiences with switching to an advertisement-free browser for iOS devices. In my case, that means an older iPad and iPhone 5S.

My primary motivation stems from using Google Chrome on these devices to view Facebook, which has become an advertisement minefield over time. And the Facebook App (along with Messenger) are just evil. But I digress…

On my laptop, I can use Chrome with the FB Purity plugin just fine, but for mobile devices, I don’t have that option. So, I downloaded Adblock Browser from the Apple AppStore a couple of weeks ago to give it a whirl.

The Good

  • It’s free
  • It works (I don’t see ads on Facebook anymore from either my iPhone or iPad)

The Bad

  • It’s slower than Chrome (but is it? see below)
  • It sometimes doesn’t render page content correctly without a reload

As to The Bad, it’s slowness has to do with being an integration with Safari, which to me has become not unlike InternetExplorer was to Windows back in the 2000’s timeframe. It’s just kind of a pig and doesn’t render content quickly. And then there are the times where it doesn’t render correctly, especially on my older iPad.

However, I often had plenty of regularly occurring errors with Chrome, especially when trying to request the desktop site and switching views from Timeline to Notifications to Messages, etc. I probably spent 50% or more of my time in Chrome reloading pages or otherwise killing it and restarting it.  So with Adblocker Browser being slower, maybe it’s a wash because it does have better overall rendering performance on Facebook. Perhaps this suggests that it’s Facebook’s web content handling mechanics and not the browser(s), but the end result is what counts: I don’t see ads anymore. Huzzah!