Solved

Can't get list of AWS instances

Posted on 2013-06-26
6
1,073 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
Does Powershell have you tied up in knots?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS - Powershell 7 73
Copy-Item -UseTransaction not working 2 34
View files under D drive on remote PC 2 22
Run powershell against OU 7 67
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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.

738 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