简体   繁体   中英

Not able to get instance-id from powershell in EC2 windows machin

I can able to get the instance-id from AWS EC2 windows machine's IE browser using the URL http://169.254.169.254/latest/meta-data/instance-id

In the same machine when I use Powershell command

Invoke-WebRequest http://169.254.169.254/latest/meta-data/instance-id

then I am getting below error

Invoke-WebRequest : Network Error (tcp_error) A communication error occurred: "Operation timed out" The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time. For assistance, contact your network support team. At line:1 char:1
+ Invoke-WebRequest http://169.254.169.254/latest/meta-data/instance-id
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Note: Invoke-WebRequest http://google.com is working and giving the response from PowerShell cmd.

Please anyone clarify what is this error.

What exactly does this need to do? Download data from the URL? I've never seen such a think before, but I would THINK you could use the System.Web.Uri class to do it, like so:

$var = New-Object System.Web.Uri
$var.Download("http://169.254.169.154/latest/meta-data/instance-id")

Does something like that work?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM