title: How to get the VPC Id of an EC2 instance?
body: <p>I need to identify the VpcId for the current EC2 instance using the C# AWS SDK. I have been trying to do this for a couple of hours now with no real luck. </p>
  
  <p>My current approach is something like this,</p>
  
  <pre><code>var currentInstanceId = Amazon.EC2.Util.EC2Metadata.InstanceId; // Get Current Instance Id
  
  AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
  var ec2Client = AWSClientFactory.CreateAmazonEC2Client(creds, clientRegionEndpoint);
  var instances = ec2Client.DescribeInstances();
  
  foreach (var reservation in instances.Reservations)
  {
    foreach (var instance in reservation.Instances)
    {
      if (instance.InstanceId.Equals(currentInstanceId)) // Compare Instance Id with all available instances 
        return instance.VpcId;
    }
  }
  </code></pre>
  
  <p>I feel like there should be an easier way to do this. Any help on this would be really appreciated.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>With @jbird's help I was able to achieve this using,</p>
  
  <pre><code>Amazon.EC2.Util.EC2Metadata.NetworkInterfaces.First().VpcId
  </code></pre>