簡體   English   中英

如何使用PowerShell獲取cloudformation堆棧的EC2實例IpAddress?

[英]How to get EC2 Instances IpAddress of a cloudformation stack using PowerShell?

我想使用PowerShell列出CloudFormation堆棧的EC2實例的IpAddresses。 我正在嘗試以下命令,但未返回IpAddress。

Get-CFNStackResourceList -StackName 'teststack' -LogicalResourceId 'EC2Instance' -region 'eu-west-1'

我建議與

基本示例:

PS C:\> Get-EC2InstanceStatus -InstanceId i-12345678

AvailabilityZone : us-west-2a
Events           : {}
InstanceId       : i-12345678
InstanceState    : Amazon.EC2.Model.InstanceState
Status           : Amazon.EC2.Model.InstanceStatusSummary
SystemStatus     : Amazon.EC2.Model.InstanceStatusSummary

PS C:\> $status = Get-EC2InstanceStatus -InstanceId i-12345678
PS C:\> $status.InstanceState

Code    Name
----    ----
16      running

然后,像這樣收集所有IPv4地址:

$EC2Instances = Get-EC2Instance

foreach($instance in $EC2Instances.Instances){
  $addresses = "";
  foreach($networkInterface in $instance.NetworkInterfaces){
    $addresses = $addresses, $networkInterface.PrivateIpAddresses.PrivateIpAddress -join ","
  }
  "$($instance.InstanceID): $($addresses.Trim(','))"    
}

此外,它可能是有益算像實例這樣

$filterRunning = New-Object Amazon.EC2.Model.Filter -Property @{Name = "instance-state-name"; Value = "running"}
$runningInstances = @(Get-EC2Instance -Filter $filterRunning)
# Count the running instances
$runningInstances.Count

另請參閱:AWS開發人員博客- 使用Windows PowerShell和Windows遠程管理為EC2 Windows腳本編寫腳本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM