Solved

Can't get list of AWS instances

Posted on 2013-06-26
6
1,044 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Google Storage: Standard vs. Nearline vs. Coldline

Google Cloud Storage has a number of classes to choose from. Although there are a lot in common, they vary in price and usage terms. This post explains Google Cloud Storage classes and helps to understand which  one to choose.

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now