Configuration for accessing Amazon Cloud Watch service
        /**
         * Configure HttpClient with set of defaults as well as configuration
         * from AmazonCloudWatchConfig instance
         */
        private static HttpWebRequest ConfigureWebRequest(int contentLength, AmazonCloudWatchConfig config)
        {
            HttpWebRequest request = WebRequest.Create(config.ServiceURL) as HttpWebRequest;

            if (request != null)
            {
                if (config.IsSetProxyHost() && config.IsSetProxyPort())
                {
                    WebProxy proxy = new WebProxy(config.ProxyHost, config.ProxyPort);
                    if (config.IsSetProxyUsername())
                    {
                        proxy.Credentials = new NetworkCredential(
                            config.ProxyUsername,
                            config.ProxyPassword ?? String.Empty
                            );
                    }
                    request.Proxy = proxy;
                }
                request.UserAgent     = config.UserAgent;
                request.Method        = "POST";
                request.Timeout       = 50000;
                request.ContentType   = AWSSDKUtils.UrlEncodedContent;
                request.ContentLength = contentLength;
            }

            return(request);
        }
 /// <summary>
 /// Constructs an AmazonCloudWatchClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonCloudWatch Configuration object
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key as a SecureString</param>
 /// <param name="config">The AmazonCloudWatch Configuration Object</param>
 public AmazonCloudWatchClient(string awsAccessKeyId, SecureString awsSecretAccessKey, AmazonCloudWatchConfig config)
 {
     this.awsAccessKeyId     = awsAccessKeyId;
     this.awsSecretAccessKey = awsSecretAccessKey;
     this.config             = config;
     ServicePointManager.Expect100Continue = false;
     ServicePointManager.UseNagleAlgorithm = false;
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonCloudWatch Configuration object. If the config object's
 /// UseSecureStringForAwsSecretKey is false, the AWS Secret Key
 /// is stored as a clear-text string. Please use this option only
 /// if the application environment doesn't allow the use of SecureStrings.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="config">The AmazonCloudWatch Configuration Object</param>
 public AmazonCloudWatchClient(string awsAccessKeyId, string awsSecretAccessKey, AmazonCloudWatchConfig config)
 {
     if (!String.IsNullOrEmpty(awsSecretAccessKey))
     {
         if (config.UseSecureStringForAwsSecretKey)
         {
             this.awsSecretAccessKey = new SecureString();
             foreach (char ch in awsSecretAccessKey.ToCharArray())
             {
                 this.awsSecretAccessKey.AppendChar(ch);
             }
             this.awsSecretAccessKey.MakeReadOnly();
         }
         else
         {
             clearAwsSecretAccessKey = awsSecretAccessKey;
         }
     }
     this.awsAccessKeyId = awsAccessKeyId;
     this.config         = config;
     ServicePointManager.Expect100Continue = false;
     ServicePointManager.UseNagleAlgorithm = false;
 }
        private static HttpWebRequest ConfigureWebRequest(int contentLength, AmazonCloudWatchConfig config)
        {
            HttpWebRequest request = WebRequest.Create(config.ServiceURL) as HttpWebRequest;

            if (request != null)
            {
                if (config.IsSetProxyHost() && config.IsSetProxyPort())
                {
                    WebProxy proxy = new WebProxy(config.ProxyHost, config.ProxyPort);
                    if (config.IsSetProxyUsername())
                    {
                        proxy.Credentials = new NetworkCredential(config.ProxyUsername, config.ProxyPassword ?? string.Empty);
                    }
                    request.Proxy = proxy;
                }
                request.UserAgent     = config.UserAgent;
                request.Method        = "POST";
                request.Timeout       = 0xc350;
                request.ContentType   = "application/x-www-form-urlencoded; charset=utf-8";
                request.ContentLength = contentLength;
            }
            return(request);
        }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Credentials and an
 /// AmazonCloudWatchClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(AWSCredentials credentials, AmazonCloudWatchConfig clientConfig)
     : base(credentials, clientConfig)
 {
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(AmazonCloudWatchConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config) { }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonCloudWatchClient Configuration object. If the config object's
 /// UseSecureStringForAwsSecretKey is false, the AWS Secret Key
 /// is stored as a clear-text string. Please use this option only
 /// if the application environment doesn't allow the use of SecureStrings.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonCloudWatchConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }
 private AmazonCloudWatch CreateClient()
 {
     // Submit in the region that the instance is local to
     var config = new AmazonCloudWatchConfig
     {
         ServiceURL = String.Format("http://monitoring.{0}.amazonaws.com", _region)
     };
     return new AmazonCloudWatchClient(_amazonAccessKeyId, _amazonSecretAccessKey, config);
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with the credentials defined in the App.config.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSAccessKey" value="********************"/&gt;
 ///         &lt;add key="AWSSecretKey" value="****************************************"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonElasticBeanstalkClient Configuration Object</param>
 public AmazonCloudWatchClient(AmazonCloudWatchConfig config)
     : base(new EnvironmentAWSCredentials(), config, true, AuthenticationTypes.User)
 {
 }
 /// <summary>
 /// Create a client for the Amazon CloudWatch Service with the specified configuration
 /// </summary>
 /// <param name="awsAccessKey">The AWS Access Key associated with the account</param>
 /// <param name="awsSecretAccessKey">The AWS Secret Access Key associated with the account</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc
 /// </param>
 /// <returns>An Amazon CloudWatch client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonCloudWatch CreateAmazonCloudWatchClient(
     string awsAccessKey,
     string awsSecretAccessKey, AmazonCloudWatchConfig config
     )
 {
     return new AmazonCloudWatchClient(awsAccessKey, awsSecretAccessKey, config);
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonCloudWatchClient Configuration object.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="awsSessionToken">AWS Session Token</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonCloudWatchConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig)
 {
 }
        ///     &lt;/appSettings&gt;
        /// &lt;/configuration&gt;
        /// </code>
        ///
        /// </summary>
        /// <param name="config">The AmazonCloudWatch Configuration Object</param>
        public AmazonCloudWatchClient(AmazonCloudWatchConfig config)
            : base(FallbackCredentialsFactory.GetCredentials(), config, true, AuthenticationTypes.User) { }

        /// <summary>
        /// Constructs AmazonCloudWatchClient with AWS Credentials
        /// </summary>
        /// <param name="credentials">AWS Credentials</param>
        public AmazonCloudWatchClient(AWSCredentials credentials)
            : this(credentials, new AmazonCloudWatchConfig())
        {
        }

        /// <summary>
        /// Constructs AmazonCloudWatchClient with AWS Credentials
        /// </summary>
Beispiel #13
0
 /// <summary>
 /// Constructs AmazonCloudWatchClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSAccessKey" value="********************"/&gt;
 ///         &lt;add key="AWSSecretKey" value="****************************************"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonCloudWatch Configuration Object</param>
 public AmazonCloudWatchClient(AmazonCloudWatchConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config, true, AuthenticationTypes.User) { }
        private IAmazonCloudWatch CreateClient()
        {
            // Submit in the region that was specified in the config file.
            AmazonCloudWatchConfig config = new AmazonCloudWatchConfig()
            {
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(_regionName)
            };

            return new AmazonCloudWatchClient(config);
        }
        private void SetupClient()
        {
            if (_client != null)
                return;

            AmazonCloudWatchConfig cloudWatchConfig = null;
            RegionEndpoint regionEndpoint = null;

            if (string.IsNullOrEmpty(EndPoint) && ConfigurationManager.AppSettings["AWSServiceEndpoint"] != null)
                EndPoint = ConfigurationManager.AppSettings["AWSServiceEndpoint"];

            if (string.IsNullOrEmpty(AccessKey) && ConfigurationManager.AppSettings["AWSAccessKey"] != null)
                AccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];

            if (string.IsNullOrEmpty(Secret) && ConfigurationManager.AppSettings["AWSSecretKey"] != null)
                Secret = ConfigurationManager.AppSettings["AWSSecretKey"];

            _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret);

            try
            {

                if (!string.IsNullOrEmpty(EndPoint))
                {
                    if (EndPoint.StartsWith("http"))
                    {
                        cloudWatchConfig = new AmazonCloudWatchConfig { ServiceURL = EndPoint };
                        if (string.IsNullOrEmpty(AccessKey))
                            _client = AWSClientFactory.CreateAmazonCloudWatchClient(cloudWatchConfig);
                    }
                    else
                    {
                        regionEndpoint = RegionEndpoint.GetBySystemName(EndPoint);
                        if (string.IsNullOrEmpty(AccessKey))
                            _client = AWSClientFactory.CreateAmazonCloudWatchClient(regionEndpoint);
                    }
                }
            }
            catch (AmazonServiceException)
            {
            }

            if (!string.IsNullOrEmpty(AccessKey))
                if (regionEndpoint != null)
                    _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret, regionEndpoint);
                else if (cloudWatchConfig != null)
                    _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret, cloudWatchConfig);
                else
                    _client = AWSClientFactory.CreateAmazonCloudWatchClient(AccessKey, Secret);

            //Debug
            var metricDatum = new Amazon.CloudWatch.Model.MetricDatum().WithMetricName("CloudWatchAppender").WithValue(1).WithUnit("Count");
            //_client.PutMetricData(new PutMetricDataRequest().WithNamespace("CloudWatchAppender").WithMetricData(metricDatum));
        }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 ///
 /// Example App.config with credentials set.
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSProfileName" value="AWS Default"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(AmazonCloudWatchConfig config)
     : base(FallbackCredentialsFactory.GetCredentials(), config)
 {
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Credentials and an
 /// AmazonCloudWatchClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(AWSCredentials credentials, AmazonCloudWatchConfig clientConfig)
     : base(credentials, clientConfig)
 {
 }
Beispiel #18
0
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Credentials and an
 /// AmazonCloudWatchClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(AWSCredentials credentials, AmazonCloudWatchConfig clientConfig)
     : base(credentials, clientConfig, false, AuthenticationTypes.User)
 {
 }
 /// <summary>
 /// Create a client for the Amazon CloudWatch Service with the credentials loaded from the application's
 /// default configuration, and if unsuccessful from the Instance Profile service on an EC2 instance.
 /// 
 /// Example App.config with credentials set. 
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSAccessKey" value="********************"/&gt;
 ///         &lt;add key="AWSSecretKey" value="****************************************"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 /// </summary>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon CloudWatch client</returns>
 public static AmazonCloudWatch CreateAmazonCloudWatchClient(AmazonCloudWatchConfig config)
 {
     return new AmazonCloudWatchClient(config);
 }
Beispiel #20
0
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonCloudWatchClient Configuration object. If the config object's
 /// UseSecureStringForAwsSecretKey is false, the AWS Secret Key
 /// is stored as a clear-text string. Please use this option only
 /// if the application environment doesn't allow the use of SecureStrings.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(string awsAccessKeyId, string awsSecretAccessKey, AmazonCloudWatchConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, clientConfig, AuthenticationTypes.User)
 {
 }
 /// <summary>
 /// Create a client for the Amazon CloudWatch Service with AWSCredentials and an AmazonCloudWatch Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param>
 /// <returns>An Amazon CloudWatch client</returns>
 /// <remarks>
 /// </remarks>
 public static IAmazonCloudWatch CreateAmazonCloudWatchClient(AWSCredentials credentials, AmazonCloudWatchConfig config)
 {
     return new AmazonCloudWatchClient(credentials, config);
 }
Beispiel #22
0
 /// <summary>
 /// Constructs AmazonCloudWatchClient with the credentials defined in the App.config.
 ///
 /// Example App.config with credentials set.
 /// <code>
 /// &lt;?xml version="1.0" encoding="utf-8" ?&gt;
 /// &lt;configuration&gt;
 ///     &lt;appSettings&gt;
 ///         &lt;add key="AWSAccessKey" value="********************"/&gt;
 ///         &lt;add key="AWSSecretKey" value="****************************************"/&gt;
 ///     &lt;/appSettings&gt;
 /// &lt;/configuration&gt;
 /// </code>
 ///
 /// </summary>
 /// <param name="config">The AmazonCloudWatch Configuration Object</param>
 public AmazonCloudWatchClient(AmazonCloudWatchConfig config)
     : base(new EnvironmentAWSCredentials(), config, true, AuthenticationTypes.User)
 {
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Access Key ID, AWS Secret Key and an
 /// AmazonS3 Configuration object. If the config object's
 /// UseSecureStringForAwsSecretKey is false, the AWS Secret Key
 /// is stored as a clear-text string. Please use this option only
 /// if the application environment doesn't allow the use of SecureStrings.
 /// </summary>
 /// <param name="awsAccessKeyId">AWS Access Key ID</param>
 /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(string awsAccessKeyId, string awsSecretAccessKey, AmazonCloudWatchConfig clientConfig)
     : base(awsAccessKeyId, awsSecretAccessKey, clientConfig)
 {
 }
 /// <summary>
 /// Constructs AmazonCloudWatchClient with AWS Credentials and an
 /// AmazonCloudWatchClient Configuration object.
 /// </summary>
 /// <param name="credentials">AWS Credentials</param>
 /// <param name="clientConfig">The AmazonCloudWatchClient Configuration Object</param>
 public AmazonCloudWatchClient(AWSCredentials credentials, AmazonCloudWatchConfig clientConfig)
     : base(credentials, clientConfig, AuthenticationTypes.User | AuthenticationTypes.Session)
 {
 }