Solved

Can't get list of AWS instances

Posted on 2013-06-26
6
1,081 Views
Last Modified: 2014-11-12
I'm trying to get a list of all my AWS instances but so far no luck.

$client=[Amazon.AWSClientFactory]::CreateAmazonEC2Client($Access,$Secret)
$request = New-Object Amazon.EC2.Model.DescribeInstancesRequest
$response = $client.DescribeInstances($request)

but $response doesn't contain any data to work with. If I do  $response.DescribeInstancesResult, I get an empty result.
0
Comment
Question by:Mikex13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280878
$client = [Amazon.AWSClientFactory]::CreateAmazonEC2Client($Access,$Secret)
$startReq = New-Object amazon.EC2.Model.StartInstancesRequest
$startReq.InstanceId.Add($instanceID);
$startResponse = $client.StartInstances($startReq)
$startResult = $startResponse.StartInstancesResult;
$startResult

Open in new window

0
 

Author Comment

by:Mikex13
ID: 39283175
#Sedgwick: Looking at your code, that starts an instance with a given instance ID. But what I'm after is the step before that: get a list of all instances.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39283737
Ok let me check
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 50 total points
ID: 39287873
$client=[Amazon.AWSClientFactory]::CreateAmazonEC2Client($Access,$Secret)

$request = New-Object -TypeName Amazon.EC2.Model.DescribeInstancesRequest
$response = $client.DescribeInstances($request)
foreach ($reservation in $response.DescribeInstancesResult.Reservation)
{ 
	foreach($instance in $reservation.RunningInstance)
	{

	}
}

Open in new window

0
 

Accepted Solution

by:
Mikex13 earned 0 total points
ID: 39288714
Got it to work - not only your code but also my initial code. The thing I was overlooking was the region. I thought the command would give me all the instances my "account" has access to but it only does it per region. If you don't set the region when defining the client, a default region is picked which might not be "your" region.

$client=[Amazon.AWSClientFactory]::CreateAmazonEC2Client($AccessKeyID,$SecretKeyID, $RegionEndpoint)
0
 

Author Closing Comment

by:Mikex13
ID: 39301490
Done some more research, looking at AWS SDKs and noticed the "region" parameter which I or previous posters have not mentioned before. Adding that parameter fixed my issue.
0

Featured Post

Are Your IoT Devices Out to Get You?

IoT business is booming, with manufacturers connecting any and every “thing” to the Internet. But as pressure grows to release new products faster and faster, we’re all left to wonder: is security a priority? Join our webinar on June 29th for the answer.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question