EC2 Instance Metadata.

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

Example #1
0
        private IEnumerable <string> GetItems(string key)
        {
            if (null == _availableKeys)
            {
                _availableKeys = EC2Metadata.GetItems(_path);
            }

            if (_availableKeys.Contains(key))
            {
                return(EC2Metadata.GetItems(_path + key));
            }
            else
            {
                return(new List <string>());
            }
        }
Example #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 = EC2Metadata.GetItems(_path);
            }

            if (_availableKeys.Contains(key))
            {
                _data[key] = EC2Metadata.GetData(_path + key);
                return(_data[key]);
            }
            else
            {
                return(null);
            }
        }
Example #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(EC2Metadata.GetItems(string.Format(CultureInfo.InvariantCulture, "{0}ipv4-associations/{1}", _path, publicIp)));
 }
Example #4
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(EC2Metadata.GetItems(String.Format("{0}ipv4-associations/{1}", _path, publicIp)));
 }