Example #1
0
        public void Enum()
        {
            Assert.Equal(20, AwsRegion.All.Length);

            foreach (var region in AwsRegion.All)
            {
                Assert.Same(region, AwsRegion.Get(region.Name));
            }

            // Ensure there are not any dublicates
            var names = AwsRegion.All.Select(a => a.Name).Distinct().ToArray();

            Assert.Equal(AwsRegion.All.Length, names.Length);
        }
Example #2
0
        public static S3Client Create(string keyId, string accessKey, AwsRegion region)
        {
            ServiceCollection services = new ServiceCollection();

            services.AddSimpleS3(s3Config =>
            {
                s3Config.Credentials = new StringAccessKey(keyId, accessKey);
                s3Config.Region      = region;
            });

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            return(serviceProvider.GetRequiredService <S3Client>());
        }
Example #3
0
 public GetPresignedUrlRequest(
     string method,
     string host,
     AwsRegion region,
     string bucketName,
     string objectKey,
     TimeSpan expiresIn)
 {
     Method     = method ?? throw new ArgumentException(nameof(method));
     Host       = host ?? throw new ArgumentNullException(nameof(host));
     Region     = region;
     BucketName = bucketName ?? throw new ArgumentNullException(nameof(bucketName));
     Key        = objectKey;
     ExpiresIn  = expiresIn;
 }
Example #4
0
        public SnsTopic(AwsRegion region, string accountId, string topicName, IAwsCredential credential)
        {
            if (accountId is null)
            {
                throw new ArgumentNullException(nameof(accountId));
            }

            if (topicName is null)
            {
                throw new ArgumentNullException(nameof(topicName));
            }

            this.client = new SnsClient(region, credential);
            this.arn    = $"arn:aws:sns:{region}:{accountId}:{topicName}";
        }
Example #5
0
        public SqsQueue(AwsRegion region, string accountId, string queueName, IAwsCredential credential)
        {
            if (accountId is null)
            {
                throw new ArgumentNullException(nameof(accountId));
            }

            if (queueName is null)
            {
                throw new ArgumentNullException(nameof(queueName));
            }

            this.url = new Uri($"https://sqs.{region}.amazonaws.com/{accountId}/{queueName}");

            this.client = new SqsClient(region, credential);
        }
 public IAmazonDynamoDB GetClient(AwsRegion region)
 {
     if (string.IsNullOrEmpty(localDbEndpoint))
     {
         RegionEndpoint regionEndpoint = GetRegionEndpoint(region);
         return(new AmazonDynamoDBClient(regionEndpoint));
     }
     else
     {
         AmazonDynamoDBConfig config = new AmazonDynamoDBConfig
         {
             ServiceURL = localDbEndpoint,
         };
         return(new AmazonDynamoDBClient(config));
     }
 }
Example #7
0
        public static S3Client Create(string keyId, string accessKey, AwsRegion region, IWebProxy?proxy = null)
        {
            //In this example we are using using Microsoft's Dependency Injection (DI) framework
            ServiceCollection services = new ServiceCollection();

            //We use Microsoft.Extensions.Configuration framework here to load our config file
            ConfigurationBuilder configBuilder = new ConfigurationBuilder();

            configBuilder.AddJsonFile("Config.json", false);
            IConfigurationRoot root = configBuilder.Build();

            //We use Microsoft.Extensions.Logging here to add support for logging
            services.AddLogging(x =>
            {
                x.AddConsole();
                x.AddConfiguration(root.GetSection("Logging"));
            });

            //Here we bind the configuration from above to S3Config, which is automatically used by SimpleS3
            services.Configure <S3Config>(root);

            //Here we create a core client without a network driver
            ICoreBuilder coreBuilder = services.AddSimpleS3Core(s3Config =>
            {
                s3Config.Credentials = new StringAccessKey(keyId, accessKey);
                s3Config.Region      = region;

                //Note that you can also override other configuration values here, even if they were bound to something else above. The values here take precedence.
            });

            //The default client is HttpClientFactory, but to show how we can change this, we use HttpClient here.
            IHttpClientBuilder httpBuilder = coreBuilder.UseHttpClient();

            if (proxy != null)
            {
                httpBuilder.WithProxy(proxy);
            }

            //This adds the S3Client service. This service combines ObjectClient, MultipartClient and BucketClient into a single client. Makes it easier for new people to use the library.
            coreBuilder.UseS3Client();

            //Finally we build the service provider and return the S3Client
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            return(serviceProvider.GetRequiredService <S3Client>());
        }
Example #8
0
        public S3Request(HttpMethod method, AwsRegion region, string bucketName, string objectName, string version = null)
        {
            #region Preconditions

            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            if (bucketName == null)
            {
                throw new ArgumentNullException(nameof(bucketName));
            }

            #endregion

            BucketName = bucketName;
            ObjectName = objectName;

            // https://{bucket}.s3.amazonaws.com/{key}

            var urlBuilder = new StringBuilder()
                             .Append("https://")
                             .Append(bucketName)
                             .Append(".")
                             .Append(S3Host.Get(region))
                             .Append("/");

            // s3.dualstack.{region.Name}.amazonaws.com

            if (objectName != null)
            {
                urlBuilder.Append(objectName);
            }

            if (version != null)
            {
                urlBuilder.Append("?version=");
                urlBuilder.Append(version);
            }

            RequestUri       = new Uri(urlBuilder.ToString());
            Method           = method;
            CompletionOption = HttpCompletionOption.ResponseHeadersRead;
        }
        public static string GetWorldSegment(this AwsRegion region)
        {
            switch (region)
            {
            case AwsRegion.ApEast1:
            case AwsRegion.ApNorthEast1:
            case AwsRegion.ApNorthEast2:
            case AwsRegion.ApNorthEast3:
            case AwsRegion.ApSouth1:
            case AwsRegion.ApSouthEast1:
            case AwsRegion.ApSouthEast2:
                return("Asia Pacific");

            case AwsRegion.CaCentral1:
                return("Canada");

            case AwsRegion.CnNorth1:
            case AwsRegion.CnNorthWest1:
                return("China");

            case AwsRegion.EuCentral1:
            case AwsRegion.EuNorth1:
            case AwsRegion.EuWest1:
            case AwsRegion.EuWest2:
            case AwsRegion.EuWest3:
                return("EU");

            case AwsRegion.SaEast1:
                return("South America");

            case AwsRegion.UsEast1:
            case AwsRegion.UsEast2:
            case AwsRegion.UsWest1:
            case AwsRegion.UsWest2:
                return("US");

            case AwsRegion.MeSouth1:
                return("Middle East");

            default:
                throw new ArgumentOutOfRangeException(nameof(region), region, null);
            }
        }
Example #10
0
        public SnsTopic(AwsRegion region, string accountId, string topicName, IAwsCredentials credentials)
        {
            #region Preconditions

            if (accountId == null)
            {
                throw new ArgumentNullException(nameof(accountId));
            }

            if (topicName == null)
            {
                throw new ArgumentNullException(nameof(topicName));
            }

            #endregion

            this.client = new SnsClient(region, credentials);
            this.arn    = $"arn:aws:sns:{region}:{accountId}:{topicName}";
        }
Example #11
0
        public ListBucketRequest(AwsRegion region, string bucketName, ListBucketOptions options)
            : base(HttpMethod.Get, region, bucketName, null)
        {
            options.QueryList.Add("list-type", "2");

            if (options.QueryList.Count > 0)
            {
                RequestUri = new Uri(RequestUri.ToString() + options.QueryList.ToQueryString());
            }

            CompletionOption = HttpCompletionOption.ResponseContentRead;

            /*
             *          GET ?prefix=photos/2006/&delimiter=/ HTTP/1.1
             *          Host: quotes.s3.amazonaws.com
             *          Date: Wed, 01 Mar  2009 12:00:00 GMT
             *          Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE=
             */
        }
Example #12
0
        public UploadPartRequest(AwsRegion region, string bucketName, string key, string uploadId, int partNumber)
            : base(region, bucketName, key + $"?partNumber={partNumber}&uploadId={uploadId}")
        {
            #region Preconditions

            if (uploadId == null)
            {
                throw new ArgumentNullException(nameof(uploadId));
            }

            if (partNumber < 1 || partNumber > 10000)
            {
                throw new ArgumentOutOfRangeException(nameof(partNumber), partNumber, "Must be between 1 and 10,000");
            }

            #endregion

            UploadId   = uploadId;
            PartNumber = partNumber;
        }
Example #13
0
 /// <summary>
 /// Initialize the object.
 /// </summary>
 /// <param name="accessKey">Access key with which to access AWS S3.</param>
 /// <param name="secretKey">Secret key with which to access AWS S3.</param>
 /// <param name="region">AWS region.</param>
 /// <param name="bucket">Bucket in which to store BLOBs.</param>
 public AwsSettings(string accessKey, string secretKey, AwsRegion region, string bucket)
 {
     if (String.IsNullOrEmpty(accessKey))
     {
         throw new ArgumentNullException(nameof(accessKey));
     }
     if (String.IsNullOrEmpty(secretKey))
     {
         throw new ArgumentNullException(nameof(secretKey));
     }
     if (String.IsNullOrEmpty(bucket))
     {
         throw new ArgumentNullException(nameof(bucket));
     }
     Endpoint  = null;
     Ssl       = true;
     AccessKey = accessKey;
     SecretKey = secretKey;
     Region    = region;
     Bucket    = bucket;
 }
        public void ExtendFrom(SubscriptionConfiguration parent)
        {
            if (parent == null)
            {
                return;
            }

            if (parent.Id.HasValue())
            {
                Id = Id.HasValue() ? parent.Id + "." + Id : parent.Id;
            }

            Enabled ??= parent.Enabled;
            Comments        = Comments.Or(parent.Comments);
            AwsRegion       = AwsRegion.Or(parent.AwsRegion);
            LogGroupName    = LogGroupName.Or(parent.LogGroupName);
            LogGroupPattern = LogGroupPattern.Or(parent.LogGroupPattern);

            StartTimeIso = StartTimeIso.Or(parent.StartTimeIso);
            EndTimeIso   = EndTimeIso.Or(parent.EndTimeIso);
            StartTimeSecondsAgo ??= parent.StartTimeSecondsAgo;
            EndTimeSecondsAgo ??= parent.EndTimeSecondsAgo;

            EventFilterPattern  = EventFilterPattern.Or(parent.EventFilterPattern);
            LogStreamNamePrefix = LogStreamNamePrefix.Or(parent.LogStreamNamePrefix);
            if (parent.LogStreamNames.SafeAny())
            {
                LogStreamNames = LogStreamNames.SafeUnion(parent.LogStreamNames).ToList();
            }

            ReadMaxBatchSize ??= parent.ReadMaxBatchSize;
            MinIntervalSeconds ??= parent.MinIntervalSeconds;
            MaxIntervalSeconds ??= parent.MaxIntervalSeconds;
            ClockSkewProtectionSeconds ??= parent.ClockSkewProtectionSeconds;

            TargetUrl = TargetUrl.Or(parent.TargetUrl);
            TargetTimeoutSeconds ??= parent.TargetTimeoutSeconds;
            TargetMaxBatchSize ??= parent.TargetMaxBatchSize;
            TargetSubscriptionData = TargetSubscriptionData.Or(parent.TargetSubscriptionData);
        }
Example #15
0
        public static S3Client Create(string keyId, string accessKey, AwsRegion region, IWebProxy proxy = null)
        {
            //In this example we are using Dependency Injection (DI) using Microsoft's DI framework
            ServiceCollection services = new ServiceCollection();

            //We use Microsoft.Extensions.Configuration framework here to load our config file
            ConfigurationBuilder configBuilder = new ConfigurationBuilder();

            configBuilder.AddJsonFile("Config.json", false);
            IConfigurationRoot root = configBuilder.Build();

            //We use Microsoft.Extensions.Logging here to add support for logging
            services.AddLogging(x =>
            {
                x.AddConsole();
                x.AddConfiguration(root.GetSection("Logging"));
            });

            //Here we create a core client without a network driver
            ICoreBuilder coreBuilder = services.AddSimpleS3Core(s3Config =>
            {
                root.Bind(s3Config);

                s3Config.Credentials = new StringAccessKey(keyId, accessKey);
                s3Config.Region      = region;
            });

            //The default client is HttpClientFactory, but to show how we can change this, we use HttpClient here.
            coreBuilder.UseHttpClient()
            .WithProxy(proxy);

            //This adds the S3Client service
            coreBuilder.UseS3Client();

            //Finally we build the service provider and return the S3Client
            IServiceProvider serviceProvider = services.BuildServiceProvider();

            return(serviceProvider.GetRequiredService <S3Client>());
        }
Example #16
0
        public KmsProtector(AwsRegion region, IAwsCredentials credentials, string keyId)
        {
            #region Preconditions

            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            if (keyId == null)
            {
                throw new ArgumentNullException(nameof(keyId));
            }

            #endregion

            this.client = new KmsClient(region, credentials);
            this.keyId  = keyId;
        }
        public static Task <PutBucketResponse> PutBucketAsync(this IS3BucketClient client, string bucketName, AwsRegion region, CancellationToken token = default)
        {
            Validator.RequireNotNull(client);
            Validator.RequireNotNull(bucketName);

            return(client.PutBucketAsync(bucketName, req => req.Region = region, token));
        }
Example #18
0
 public SnsClient(AwsRegion region, IAwsCredential credential)
     : base(AwsService.Sns, region, credential)
 {
 }
Example #19
0
 public DynamoDbClient(AwsRegion region, IAwsCredential credential)
     : base(AwsService.DynamoDb, region, credential)
 {
     httpClient.Timeout = TimeSpan.FromSeconds(10);
 }
Example #20
0
 public AddBucketRequest(AwsRegion region, string bucketName)
     : base(HttpMethod.Put, region, bucketName, null)
 {
 }
Example #21
0
 public RdsService(AwsRegion region, IAwsCredential credential)
 {
     this.region     = region ?? throw new ArgumentNullException(nameof(region));
     this.credential = credential ?? throw new ArgumentNullException(nameof(credential));
 }
Example #22
0
 public LambdaClient(AwsRegion region, IAwsCredential credential)
     : base(AwsService.Lambda, region, credential)
 {
 }
Example #23
0
 public S3Bucket(AwsRegion region, string bucketName, IAwsCredential credential)
     : this(bucketName, new S3Client(region, credential))
 {
 }
Example #24
0
 public S3Client(AwsRegion region, IAwsCredential credential)
     : this(region, host : $"s3.dualstack.{region.Name}.amazonaws.com", credential : credential)
 {
 }
Example #25
0
 public ElbClient(AwsRegion region, IAwsCredential credential)
     : base(AwsService.Elb, region, credential)
 {
 }
Example #26
0
 public PutObjectRequest(AwsRegion region, string bucketName, string key)
     : base(HttpMethod.Put, region, bucketName, key)
 {
     CompletionOption = HttpCompletionOption.ResponseContentRead;
 }
Example #27
0
 public S3Client(AwsRegion region, string host, IAwsCredential credential)
     : base(AwsService.S3, region, credential)
 {
     Host = host ?? throw new ArgumentNullException(nameof(host));
 }
Example #28
0
 public DeleteObjectRequest(AwsRegion region, string bucketName, string key, string version = null)
     : base(HttpMethod.Delete, region, bucketName, key, version)
 {
 }
Example #29
0
 public CodeBuildClient(AwsRegion region, IAwsCredential credential)
     : base(AwsService.CodeBuild, region, credential)
 {
 }
Example #30
0
        public static RegionEndpoint ToRegionEndpoint(this AwsRegion region)
        {
            switch (region)
            {
            case AwsRegion.USEast1:
                return(RegionEndpoint.USEast1);

            case AwsRegion.USEast2:
                return(RegionEndpoint.USEast2);

            case AwsRegion.USWest1:
                return(RegionEndpoint.USWest1);

            case AwsRegion.USWest2:
                return(RegionEndpoint.USWest2);

            case AwsRegion.EUNorth1:
                return(RegionEndpoint.EUNorth1);

            case AwsRegion.EUWest1:
                return(RegionEndpoint.EUWest1);

            case AwsRegion.EUWest2:
                return(RegionEndpoint.EUWest2);

            case AwsRegion.EUWest3:
                return(RegionEndpoint.EUWest3);

            case AwsRegion.EUCentral1:
                return(RegionEndpoint.EUCentral1);

            case AwsRegion.EUSouth1:
                return(RegionEndpoint.EUSouth1);

            case AwsRegion.APEast1:
                return(RegionEndpoint.APEast1);

            case AwsRegion.APNortheast1:
                return(RegionEndpoint.APNortheast1);

            case AwsRegion.APNortheast2:
                return(RegionEndpoint.APNortheast2);

            case AwsRegion.APNortheast3:
                return(RegionEndpoint.APNortheast3);

            case AwsRegion.APSouth1:
                return(RegionEndpoint.APSouth1);

            case AwsRegion.APSoutheast1:
                return(RegionEndpoint.APSoutheast1);

            case AwsRegion.APSoutheast2:
                return(RegionEndpoint.APSoutheast2);

            case AwsRegion.SAEast1:
                return(RegionEndpoint.SAEast1);

            case AwsRegion.USGovCloudEast1:
                return(RegionEndpoint.USGovCloudEast1);

            case AwsRegion.USGovCloudWest1:
                return(RegionEndpoint.USGovCloudWest1);

            case AwsRegion.CNNorth1:
                return(RegionEndpoint.CNNorth1);

            case AwsRegion.CNNorthWest1:
                return(RegionEndpoint.CNNorthWest1);

            case AwsRegion.CACentral1:
                return(RegionEndpoint.CACentral1);

            case AwsRegion.MESouth1:
                return(RegionEndpoint.MESouth1);

            case AwsRegion.AFSouth1:
                return(RegionEndpoint.AFSouth1);
            }

            return(null);
        }