Getting a list of your AMIs from Amazon AWS

I just ran into a problem running some code that worked the last time I ran it. Code that was calling DescribeImages on the Amazon Web Services (AWS) API. It was a really odd problem because my particular line of code was just calling the DescribeImages() method on the AmazonEC2Client which never returned and just blocked forever.

Well, it used to work…

I watched the request again the AWS REST API happen in Fiddler, which was also not very helpful. Anything I tried to do to the request would result in a response from the API that would never send a body.

To fix the problem, I had to be more specific and create a DescribeImagesRequest. Fortunately, I didn’t actually want to receive a list of ALL of my AMIs, but rather just look up the ID of a specific AMI by name. My before/after code is below:

Before

return client.DescribeImages().Images.Single(x => x.Name == amiName).ImageId;

After

var images = client.DescribeImages(new DescribeImagesRequest() { Filters = new List() { new Filter("name", new List() { amiName }) } });
return images.Images.Single().ImageId;

Hopefully this helps someone running into the same problem.

Leave a Reply

Your email address will not be published. Required fields are marked *