Solved

Can't get list of AWS instances

Posted on 2013-06-26
6
1,068 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
  • 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

There is no doubt that cloud is gaining importance. Many of you must have read about this technology and its growing importance. More and more organisations are embracing this technology not forgetting start-ups. The process begins by dipping …
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This Micro Tutorial will explain how to export DynamoDB tables in Amazon Web Services.

828 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