Provides access to EC2 instance metadata when running on an EC2 instance.

Amazon EC2 instances can access instance-specific metadata, as well as data supplied when launching the instances, using a specific URI.

You can use this data to build more generic AMIs that can be modified by configuration files supplied at launch time. For example, if you run web servers for various small businesses, they can all use the same AMI and retrieve their content from the Amazon S3 bucket you specify at launch. To add a new customer at any time, simply create a bucket for the customer, add their content, and launch your AMI.

More information about EC2 Metadata

Exemplo n.º 1
0
        private IEnumerable <string> GetItems(string key)
        {
            if (null == _availableKeys)
            {
                _availableKeys = EC2InstanceMetadata.GetItems(_path);
            }

            if (_availableKeys.Contains(key))
            {
                return(EC2InstanceMetadata.GetItems(_path + key));
            }
            else
            {
                return(new List <string>());
            }
        }
Exemplo n.º 2
0
        private string GetData(string key)
        {
            if (_data.ContainsKey(key))
            {
                return(_data[key]);
            }

            // Since the keys are variable, cache a list of which ones are available
            // to prevent unnecessary trips to the service.
            if (null == _availableKeys)
            {
                _availableKeys = EC2InstanceMetadata.GetItems(_path);
            }

            if (_availableKeys.Contains(key))
            {
                _data[key] = EC2InstanceMetadata.GetData(_path + key);
                return(_data[key]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get the private IPv4 address(es) that are associated with the public-ip address and assigned to that interface.
 /// </summary>
 /// <param name="publicIp">The public IP address</param>
 /// <returns>Private IPv4 address(es) associated with the public IP address</returns>
 public IEnumerable <string> GetIpV4Association(string publicIp)
 {
     return(EC2InstanceMetadata.GetItems(string.Format(CultureInfo.InvariantCulture, "{0}ipv4-associations/{1}", _path, publicIp)));
 }