public BaseAmazonDiscoveryHttpClient(string serviceNamespace,
                                             string serviceName,
                                             AmazonConfiguration amazonConfiguration,
                                             HttpClient client) : base(client)
        {
            var discoverClient = new AmazonServiceDiscoveryClient(amazonConfiguration.Credentials,
                                                                  amazonConfiguration.RegionEndpoint);

            var discoverInstanceRequest = new DiscoverInstancesRequest
            {
                ServiceName   = serviceName,
                NamespaceName = serviceNamespace,
                HealthStatus  = HealthStatus.HEALTHY.Value
            };

            var discoveryTask = discoverClient.DiscoverInstancesAsync(discoverInstanceRequest);

            discoveryTask.Wait();

            var instances = discoveryTask.Result.Instances;

            var instance = instances.FirstOrDefault();

            var ipv4 = instance.Attributes["AWS_INSTANCE_IPV4"];
            var port = instance.Attributes["AWS_INSTANCE_PORT"];

            _baseUrl = $"http://{ipv4}:{port}";
        }
Ejemplo n.º 2
0
        private void ConfigureLogger(ILoggerFactory loggerFactory, AmazonConfiguration amazonConfiguration)
        {
            var loggerConfig = Configuration.GetAWSLoggingConfigSection();

            loggerConfig.Config.Credentials = amazonConfiguration.Credentials;

            loggerFactory.AddAWSProvider(loggerConfig, formatter: (logLevel, message, exception) => $"[{DateTime.UtcNow}] {logLevel}: {message}");
        }
Ejemplo n.º 3
0
        public static void AddAwsConfiguration(this IServiceCollection services)
        {
            var accessKey = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY");
            var secretKey = Environment.GetEnvironmentVariable("AWS_SECRET_KEY");

            var region = RegionEndpoint.USEast2;

            var credentials = new BasicAWSCredentials(accessKey, secretKey);

            var amazonConfig = new AmazonConfiguration(credentials, region);

            services.AddSingleton(amazonConfig);
        }
Ejemplo n.º 4
0
 public AmazonFileRepository()
 {
     this.amazonConfig = new AmazonConfiguration();
 }
Ejemplo n.º 5
0
 public MessageService(IAmazonClient <AmazonSQSClient> amazonClient, IOptions <AmazonConfiguration> amazonConfiguration)
 {
     _amazonClient        = amazonClient;
     _amazonConfiguration = amazonConfiguration.Value;
     _sqsClient           = _amazonClient.GetClient(_amazonConfiguration.ServiceURL).Result;
 }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, AmazonConfiguration amazonConfiguration)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            ConfigureLogger(loggerFactory, amazonConfiguration);

            app.UseMvc();
        }
Ejemplo n.º 7
0
 public AmazonClientService(IOptions <AmazonConfiguration> amazonConfiguration)
 {
     _amazonConfiguration = amazonConfiguration.Value;
     _ = GetClient(_amazonConfiguration.ServiceURL);
 }