/// <summary>
        /// Opens the component.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        public async Task OpenAsync(string correlationId)
        {
            if (_opened)
            {
                return;
            }

            var awsConnection = await _connectionResolver.ResolveAsync(correlationId);

            // Validate connection params
            var err = awsConnection.Validate(correlationId);

            if (err != null)
            {
                throw err;
            }

            // Create client
            var region = RegionEndpoint.GetBySystemName(awsConnection.Region);
            var config = new AmazonCloudWatchConfig()
            {
                RegionEndpoint = region
            };

            _client = new AmazonCloudWatchClient(awsConnection.AccessId, awsConnection.AccessKey, config);
            _opened = true;

            await Task.Delay(0);
        }
コード例 #2
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonCloudWatchConfig config = new AmazonCloudWatchConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonCloudWatchClient client = new AmazonCloudWatchClient(creds, config);

            ListMetricsResponse resp = new ListMetricsResponse();

            do
            {
                ListMetricsRequest req = new ListMetricsRequest
                {
                    NextToken = resp.NextToken
                };

                resp = client.ListMetrics(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Metrics)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
コード例 #3
0
 /// <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));
 }
コード例 #4
0
        public override IAmazonCloudWatch CreateCloudWatchClient()
        {
            var config = new AmazonCloudWatchConfig()
            {
                RegionEndpoint = AWSRegion
            };

            return(new AmazonCloudWatchClient(Credentials, config));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public IAmazonCloudWatch CreateClient()
        {
            var config = new AmazonCloudWatchConfig();

            config.ProxyHost      = "localstack";
            config.ProxyPort      = 4582;
            config.UseHttp        = true;
            config.RegionEndpoint = RegionEndpoint.USEast1;
            config.ServiceURL     = "http://localhost:4582/";
            config.BufferSize     = 0;

            return(new AmazonCloudWatchClient(config));
        }
コード例 #7
0
        protected IAmazonCloudWatch CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonCloudWatchConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonCloudWatchClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
コード例 #8
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonCloudWatchConfig config = new AmazonCloudWatchConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonCloudWatchClient client = new AmazonCloudWatchClient(creds, config);

            DescribeAlarmsForMetricResponse resp = new DescribeAlarmsForMetricResponse();
            DescribeAlarmsForMetricRequest  req  = new DescribeAlarmsForMetricRequest
            {
            };

            resp = client.DescribeAlarmsForMetric(req);
            CheckError(resp.HttpStatusCode, "200");

            foreach (var obj in resp.MetricAlarms)
            {
                AddObject(obj);
            }
        }
コード例 #9
0
 /// <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));
 }
コード例 #10
0
        private void SetupClient(ClientConfig clientConfig)
        {
            if (Client != null)
            {
                return;
            }

            if (clientConfig == null)
            {
                if (typeof(T) == typeof(AmazonCloudWatchLogsClient))
                {
                    clientConfig = new AmazonCloudWatchLogsConfig();
                }
                else
                {
                    clientConfig = new AmazonCloudWatchConfig();
                }
            }


            if (string.IsNullOrEmpty(_endPoint) && clientConfig.RegionEndpoint == null && 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"];
            }

            if (!string.IsNullOrEmpty(_endPoint))
            {
                if (_endPoint.StartsWith("http"))
                {
                    clientConfig.ServiceURL = _endPoint;
                }
                else
                {
                    clientConfig.RegionEndpoint = RegionEndpoint.GetBySystemName(_endPoint);
                }
            }

            if (string.IsNullOrEmpty(_accessKey))
            {
                try
                {
                    if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["AWSProfileName"]) || ProfileManager.ListProfileNames().Contains("default"))
                    {
                        if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["AWSRegion"]))
                        {
                            Client = AWSClientFactoryWrapper <T> .CreateServiceClient();
                        }
                        else if (clientConfig.RegionEndpoint != null)
                        {
                            Client = AWSClientFactoryWrapper <T> .CreateServiceClient(clientConfig);
                        }
                    }
                    else
                    {
                        foreach (var availableRole in InstanceProfileAWSCredentials.GetAvailableRoles())
                        {
                            LogLog.Debug(typeof(CloudWatchClientWrapperBase <>), "Role: " + availableRole);
                        }
                        Client = AWSClientFactoryWrapper <T> .CreateServiceClient(clientConfig);
                    }
                }
                catch (AmazonServiceException e)
                {
                    LogLog.Debug(typeof(CloudWatchClientWrapperBase <>), "Exception caught while creating client", e);
                }
            }