Ejemplo n.º 1
0
        private static void ConfigureServices(IServiceCollection serviceCollection)
        {
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("KEY")))
            {
                throw new Exception("Missing KEY environment variable");
            }
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SECRET")))
            {
                throw new Exception("Missing SECRET environment variable");
            }
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("REGION")))
            {
                throw new Exception("Missing REGION environment variable");
            }

            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Bucket")))
            {
                throw new Exception("Missing Bucket environment variable");
            }
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Queue")))
            {
                throw new Exception("Missing Queue environment variable");
            }
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("Table")))
            {
                throw new Exception("Missing Table environment variable");
            }

            serviceCollection.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConsole();
                loggingBuilder.AddDebug();
            });


            var awsConfig = new AwsConfig
            {
                AccessKey = Environment.GetEnvironmentVariable("KEY"),
                SecretKey = Environment.GetEnvironmentVariable("SECRET"),
                Region    = Environment.GetEnvironmentVariable("REGION"),
                Bucket    = Environment.GetEnvironmentVariable("Bucket"),
                Queue     = Environment.GetEnvironmentVariable("Queue"),
                Table     = Environment.GetEnvironmentVariable("Table")
            };

            serviceCollection.AddSingleton(awsConfig);
            serviceCollection.AddTransient <IAwsManagers, AwsManagers>();
            serviceCollection.AddSingleton <App>();
        }
Ejemplo n.º 2
0
        public AwsManagers(AwsConfig config)
        {
            var options = new AWSOptions
            {
                Credentials = new BasicAWSCredentials(config.AccessKey, config.SecretKey),
                Region      = RegionEndpoint.GetBySystemName(config.Region)
            };

            s3Client       = options.CreateServiceClient <IAmazonS3>();
            sqsCLient      = options.CreateServiceClient <IAmazonSQS>();
            textractClient = options.CreateServiceClient <IAmazonTextract>();


            dbClient = new AmazonDynamoDBClient(config.AccessKey, config.SecretKey, RegionEndpoint.GetBySystemName(config.Region));

            bucketName = config.Bucket;
            queueUrl   = config.Queue;
            tableName  = config.Table;
        }