public AWSClass() { if (clients3 == null) clients3 = new AmazonS3Client(Amazon.RegionEndpoint.USWest2); if(clientsns == null) clientsns = new AmazonSimpleNotificationServiceClient(); }
/// <summary> /// Initializes a new instance of the <see cref="MultipartUploadCommand"/> class. /// </summary> /// <param name="s3Client">The s3 client.</param> /// <param name="config">The config object that has the number of threads to use.</param> /// <param name="fileTransporterRequest">The file transporter request.</param> internal MultipartUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest) { this._config = config; if (fileTransporterRequest.IsSetFilePath()) { _logger.DebugFormat("Beginning upload of file {0}.", fileTransporterRequest.FilePath); } else { _logger.DebugFormat("Beginning upload of stream."); } this._s3Client = s3Client; this._fileTransporterRequest = fileTransporterRequest; this._contentLength = this._fileTransporterRequest.ContentLength; if (fileTransporterRequest.IsSetPartSize()) this._partSize = fileTransporterRequest.PartSize; else this._partSize = calculatePartSize(this._contentLength); if (fileTransporterRequest.InputStream != null) { if (fileTransporterRequest.AutoResetStreamPosition && fileTransporterRequest.InputStream.CanSeek) { fileTransporterRequest.InputStream.Seek(0, SeekOrigin.Begin); } } _logger.DebugFormat("Upload part size {0}.", this._partSize); }
public AlbumCacheTask(ILastfmClientFactory lastfmFactory, IS3ClientFactory s3Factory, ICacheProvider cacheProvider, ILogger<AlbumCacheTask> logger) { this.s3Client = s3Factory.CreateS3Client(); this.lastfmClient = lastfmFactory.CreateLastfmClient(); this.cacheProvider = cacheProvider; this.logger = logger; }
public BloomS3Client(string bucketName) { _bucketName = bucketName; _amazonS3 = AWSClientFactory.CreateAmazonS3Client(KeyManager.S3AccessKey, KeyManager.S3SecretAccessKey, new AmazonS3Config { ServiceURL = "https://s3.amazonaws.com" }); _transferUtility = new TransferUtility(_amazonS3); }
public static TransportMessage ToTransportMessage(this SqsTransportMessage sqsTransportMessage, IAmazonS3 amazonS3, SqsConnectionConfiguration connectionConfiguration) { var messageId = sqsTransportMessage.Headers[Headers.MessageId]; var result = new TransportMessage(messageId, sqsTransportMessage.Headers); if (!string.IsNullOrEmpty(sqsTransportMessage.S3BodyKey)) { var s3GetResponse = amazonS3.GetObject(connectionConfiguration.S3BucketForLargeMessages, sqsTransportMessage.S3BodyKey); result.Body = new byte[s3GetResponse.ResponseStream.Length]; using (BufferedStream bufferedStream = new BufferedStream(s3GetResponse.ResponseStream)) { int count; int transferred = 0; while ((count = bufferedStream.Read(result.Body, transferred, 8192)) > 0) { transferred += count; } } } else { result.Body = Convert.FromBase64String(sqsTransportMessage.Body); } result.TimeToBeReceived = sqsTransportMessage.TimeToBeReceived; if (sqsTransportMessage.ReplyToAddress != null) { result.Headers[Headers.ReplyToAddress] = sqsTransportMessage.ReplyToAddress.ToString(); } return result; }
internal SimpleUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest) { this._s3Client = s3Client; this._config = config; this._fileTransporterRequest = fileTransporterRequest; var fileName = fileTransporterRequest.FilePath; }
protected S3PutBase(IAmazonS3 amazonS3) { if (null == amazonS3) throw new ArgumentNullException(nameof(amazonS3)); AmazonS3 = amazonS3; }
internal AbortMultipartUploadsCommand(IAmazonS3 s3Client, string bucketName, DateTime initiateDate, TransferUtilityConfig config) { this._s3Client = s3Client; this._bucketName = bucketName; this._initiatedDate = initiateDate; this._config = config; }
public override byte[] DownloadToByteArray(string container, string fileName) { client = AWSClientFactory.CreateAmazonS3Client(ExtendedProperties["accessKey"], ExtendedProperties["secretKey"], RegionEndpoint.USEast1); String S3_KEY = fileName; GetObjectRequest request = new GetObjectRequest() { BucketName = container, Key = S3_KEY, }; GetObjectResponse response = client.GetObject(request); int numBytesToRead = (int)response.ContentLength; int numBytesRead = 0; byte[] buffer = new byte[numBytesToRead]; while (numBytesToRead > 0) { int n = response.ResponseStream.Read(buffer, numBytesRead, numBytesToRead); if (n == 0) break; numBytesRead += n; numBytesToRead -= n; } return buffer; }
public ScreenshotUploader(Secrets secrets, string userToken, IMessageBus messageBus) { this._bucket = secrets.Name; this._token = userToken; this._client = new AmazonS3Client(secrets.Key, secrets.Secret, RegionEndpoint.USEast1); this._messageBus = messageBus; }
public static void PutBucketToS3(string _bucketname) { if (clients3 == null) clients3 = new AmazonS3Client(Amazon.RegionEndpoint.USWest2); try { PutBucketRequest request = new PutBucketRequest() { BucketName = _bucketname, BucketRegion = S3Region.USW2, CannedACL = S3CannedACL.PublicRead }; PutBucketResponse response = clients3.PutBucket(request); } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { Console.WriteLine("Check the provided AWS Credentials."); Console.WriteLine( "For service sign up go to http://aws.amazon.com/s3"); } else { Console.WriteLine( "Error occurred. Message:'{0}' when writing an object" , amazonS3Exception.Message); } } }
internal static async Task<GetHeadResponse> GetHeadAsync(IAmazonS3 s3Client, IClientConfig config, string url, string header) { if (s3Client != null) { using (var httpClient = GetHttpClient(config)) { var request = new HttpRequestMessage(HttpMethod.Head, url); var response = await httpClient.SendAsync(request).ConfigureAwait(false); foreach (var headerPair in response.Headers) { if (string.Equals(headerPair.Key, HeaderKeys.XAmzBucketRegion, StringComparison.OrdinalIgnoreCase)) { foreach (var value in headerPair.Value) { // If there's more than one there's something really wrong. // So just use the first one anyway. return new GetHeadResponse { HeaderValue = value, StatusCode = response.StatusCode }; } } } } } return null; }
public static TransportMessage ToTransportMessage(this SqsTransportMessage sqsTransportMessage, IAmazonS3 amazonS3, SqsConnectionConfiguration connectionConfiguration) { var messageId = sqsTransportMessage.Headers[Headers.MessageId]; var result = new TransportMessage(messageId, sqsTransportMessage.Headers); if (!string.IsNullOrEmpty(sqsTransportMessage.S3BodyKey)) { var s3GetResponse = amazonS3.GetObject(connectionConfiguration.S3BucketForLargeMessages, sqsTransportMessage.S3BodyKey); result.Body = new byte[s3GetResponse.ResponseStream.Length]; s3GetResponse.ResponseStream.Read(result.Body, 0, result.Body.Length); } else { result.Body = Convert.FromBase64String(sqsTransportMessage.Body); } result.TimeToBeReceived = sqsTransportMessage.TimeToBeReceived; if (sqsTransportMessage.ReplyToAddress != null) { result.Headers[Headers.ReplyToAddress] = sqsTransportMessage.ReplyToAddress.ToString(); } return result; }
public S3VirtualPathProvider(IAmazonS3 client, string bucketName, IAppHost appHost) : base(appHost) { this.AmazonS3 = client; this.BucketName = bucketName; this.rootDirectory = new S3VirtualDirectory(this, null); }
public static void Main(string[] args) { if (checkRequiredFields()) { using (client = new AmazonS3Client(RegionEndpoint.USWest2)) { Console.WriteLine("Listing buckets"); ListingBuckets(); Console.WriteLine("Creating a bucket"); CreateABucket(); Console.WriteLine("Writing an object"); WritingAnObject(); Console.WriteLine("Reading an object"); ReadingAnObject(); Console.WriteLine("Deleting an object"); DeletingAnObject(); Console.WriteLine("Listing objects"); ListingObjects(); } } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public AwsManager(IAmazonS3 amazonS3, IPathManager pathManager) { if (null == amazonS3) throw new ArgumentNullException(nameof(amazonS3)); if (null == pathManager) throw new ArgumentNullException(nameof(pathManager)); _pathManager = pathManager; _amazonS3 = amazonS3; var storageClass = S3StorageClass.Standard; var storageClassString = ConfigurationManager.AppSettings["AwsStorageClass"]; if (!string.IsNullOrWhiteSpace(storageClassString)) storageClass = S3StorageClass.FindValue(storageClassString); var blobStorageClass = storageClass; var blobStorageClassString = ConfigurationManager.AppSettings["AwsBlobStorageClass"]; if (!string.IsNullOrWhiteSpace(blobStorageClassString)) blobStorageClass = S3StorageClass.FindValue(blobStorageClassString); var linkStorageClass = storageClass; var linkStorageClassString = ConfigurationManager.AppSettings["AwsLinkStorageClass"]; if (!string.IsNullOrWhiteSpace(linkStorageClassString)) linkStorageClass = S3StorageClass.FindValue(linkStorageClassString); _s3Blobs = new S3Blobs(amazonS3, pathManager, blobStorageClass); _s3Links = new S3Links(amazonS3, pathManager, linkStorageClass); }
/// <summary> /// Initializes a new instance of the <see cref="MultipartUploadCommand"/> class. /// </summary> /// <param name="s3Client">The s3 client.</param> /// <param name="config">The config object that has the number of threads to use.</param> /// <param name="fileTransporterRequest">The file transporter request.</param> internal MultipartUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest) { this._config = config; if (fileTransporterRequest.IsSetFilePath()) { _logger.DebugFormat("Beginning upload of file {0}.", fileTransporterRequest.FilePath); } else { _logger.DebugFormat("Beginning upload of stream."); } this._s3Client = s3Client; this._fileTransporterRequest = fileTransporterRequest; this._contentLength = this._fileTransporterRequest.ContentLength; if (fileTransporterRequest.IsSetPartSize()) this._partSize = fileTransporterRequest.PartSize; else this._partSize = calculatePartSize(this._contentLength); _logger.DebugFormat("Upload part size {0}.", this._partSize); }
private async Task<Album> CacheAlbum(HttpClient httpClient, IAmazonS3 s3Client, JsonAlbum jsonAlbum, IList<string> cachedObjects, CancellationToken ctx) { var image = jsonAlbum.Image.Where(i => i.Size == JsonAlbumImageSize.Medium && i.Url != null).SingleOrDefault(); if (image == null) { return null; } var album = new Album { Artist = jsonAlbum.Artist, Name = jsonAlbum.Name, Playcount = jsonAlbum.Playcount, Rank = jsonAlbum.Attributes.Rank, Url = jsonAlbum.Url }; var objectKey = album.ToString().ToSlug(); album.Thumbnail = new Uri($"https://s3-eu-west-1.amazonaws.com/{BucketName}/{objectKey}"); // If the album art was cached already, return if (cachedObjects.Any(k => k == objectKey)) { return album; } string mediaType; byte[] imageBytes; try { logger.LogInformation($"Downloading art for {album}"); var response = await httpClient.GetAsync(image.Url, ctx); mediaType = response.Content.Headers?.ContentType?.MediaType; imageBytes = await response.Content.ReadAsByteArrayAsync(); } catch (Exception ex) { // If anything happened here, log and continue. We don't want to retry. logger.LogWarning($"Hit exception whilst trying to download art for {album}", ex); return null; } PutObjectResponse putResponse; using (var ms = new MemoryStream(imageBytes)) { logger.LogVerbose($"Storing art for {album}"); putResponse = await s3Client.PutObjectAsync(new PutObjectRequest { BucketName = BucketName, ContentType = mediaType, InputStream = ms, Key = objectKey, StorageClass = S3StorageClass.ReducedRedundancy, CannedACL = S3CannedACL.PublicRead }, ctx); } return album; }
public CodeDeployProcessor(IApplicationEnvironment appEnv, IConfiguration configuration, UtilityService utilties, IAmazonS3 s3Client, IAmazonCodeDeploy codeDeployClient) { this.AppEnv = appEnv; this.Configuration = configuration; this.Utilities = utilties; this.S3Client = s3Client; this.CodeDeployClient = codeDeployClient; }
public AmazonS3StorageProvider(IAmazonS3StorageConfiguration amazonS3StorageConfiguration) { _amazonS3StorageConfiguration = amazonS3StorageConfiguration; var cred = new BasicAWSCredentials(_amazonS3StorageConfiguration.AWSAccessKey, _amazonS3StorageConfiguration.AWSSecretKey); //TODO: aws region to config _client = new AmazonS3Client(cred, RegionEndpoint.USEast1); var config = new TransferUtilityConfig(); _transferUtility = new TransferUtility(_client, config); }
/// <summary> /// Determines whether an S3 bucket exists or not. /// This is done by: /// 1. Creating a PreSigned Url for the bucket (with an expiry date at the end of this decade) /// 2. Making a HEAD request to the Url /// </summary> /// <param name="bucketName">The name of the bucket to check.</param> /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param> /// <returns></returns> public static bool DoesS3BucketExist(IAmazonS3 s3Client, string bucketName) { if (s3Client == null) { throw new ArgumentNullException("s3Client", "The s3Client cannot be null!"); } if (String.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException("bucketName", "The bucketName cannot be null or the empty string!"); } GetPreSignedUrlRequest request = new GetPreSignedUrlRequest(); request.BucketName = bucketName; if (AWSConfigs.S3Config.UseSignatureVersion4) request.Expires = DateTime.Now.AddDays(6); else request.Expires = new DateTime(2019, 12, 31); request.Verb = HttpVerb.HEAD; request.Protocol = Protocol.HTTP; string url = s3Client.GetPreSignedURL(request); Uri uri = new Uri(url); HttpWebRequest httpRequest = WebRequest.Create(uri) as HttpWebRequest; httpRequest.Method = "HEAD"; AmazonS3Client concreteClient = s3Client as AmazonS3Client; if (concreteClient != null) { concreteClient.ConfigureProxy(httpRequest); } try { using (HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse) { // If all went well, the bucket was found! return true; } } catch (WebException we) { using (HttpWebResponse errorResponse = we.Response as HttpWebResponse) { if (errorResponse != null) { HttpStatusCode code = errorResponse.StatusCode; return code != HttpStatusCode.NotFound && code != HttpStatusCode.BadRequest; } // The Error Response is null which is indicative of either // a bad request or some other problem return false; } } }
static void CreateABucket(IAmazonS3 client, string bucketName) { PutBucketRequest putRequest1 = new PutBucketRequest { BucketName = bucketName, UseClientRegion = true }; PutBucketResponse response1 = client.PutBucket(putRequest1); }
/// <summary> /// Initializes a new instance of the <see cref="AmazonS3Helper" /> class using the specified credentials. /// </summary> /// <param name="keyPublic">The public Amazon S3 key.</param> /// <param name="keySecret">The secret Amazon S3 key.</param> public AmazonS3Helper(String keyPublic, String keySecret, String bucket) { _keyPublic = keyPublic; _keySecret = keySecret; _bucket = bucket; ValidateConfiguration(); var s3Config = new AmazonS3Config { RegionEndpoint = RegionEndpoint.USEast1 }; _client = AWSClientFactory.CreateAmazonS3Client(keyPublic, _keySecret, s3Config); }
public S3FileStorage(IS3Configuration configuration, IFileRestriction fileRestriction) { var region = RegionEndpoint.GetBySystemName(configuration.Region); _fileRestriction = fileRestriction; _bucket = configuration.Bucket; _client = AWSClientFactory.CreateAmazonS3Client( configuration.AccessKeyID, configuration.AccessKeySecret, region); }
public S3Links(IAmazonS3 amazonS3, IPathManager pathManager, S3StorageClass s3StorageClass) : base(amazonS3) { if (null == pathManager) throw new ArgumentNullException(nameof(pathManager)); if (null == s3StorageClass) throw new ArgumentNullException(nameof(s3StorageClass)); _pathManager = pathManager; _s3StorageClass = s3StorageClass; }
public static void Upload_object(string keyName, string filePath) { client = new AmazonS3Client("AKIAJWLLQBVBD4TTERPQ", "JOjpTd1crgwOmL99jlhs7qDYk5gpAlDEm2FxeWa6", Amazon.RegionEndpoint.USEast1); PutObjectRequest request = new PutObjectRequest() { BucketName = bucketName, Key = keyName, FilePath = filePath }; PutObjectResponse response2 = client.PutObject(request); }
static string FindBucketLocation(IAmazonS3 client, string bucketName) { string bucketLocation; GetBucketLocationRequest request = new GetBucketLocationRequest() { BucketName = bucketName }; GetBucketLocationResponse response = client.GetBucketLocation(request); bucketLocation = response.Location.ToString(); return bucketLocation; }
public override void Upload(string container, string path, IUploadedFile file) { client = AWSClientFactory.CreateAmazonS3Client(ExtendedProperties["accessKey"], ExtendedProperties["secretKey"], RegionEndpoint.USEast1); String S3_KEY = path; PutObjectRequest request = new PutObjectRequest(); request.BucketName = container; request.Key = S3_KEY; request.InputStream = file.Stream; client.PutObject(request); }
public AmazonStorageProvider(AmazonProviderOptions options) { _serviceUrl = options.ServiceUrl ?? DefaultServiceUrl; _bucket = options.Bucket; var S3Config = new AmazonS3Config { ServiceURL = _serviceUrl }; _s3Client = new AmazonS3Client(options.PublicKey, options.SecretKey, S3Config); }
public void Dispose() { if (s3Client == null) return; try { s3Client.Dispose(); s3Client = null; } catch { } }
public static void Main() { s3Client = new AmazonS3Client(bucketRegion); Console.WriteLine("Uploading an object"); UploadObjectAsync().Wait(); }
public S3EmailMessageClient(IAggregateReportConfig config, IAmazonS3 s3Client, ILogger <S3EmailMessageClient> log) { _config = config; _s3Client = s3Client; _log = log; }
public ExtractDownloads(IAmazonS3 s3Client, DownloadConfiguration config) { _client = s3Client; _config = config; }
/// <summary> /// /// </summary> /// <param name="amazonS3"></param> /// <param name="bucketName"></param> public AmazonS3Helper(IAmazonS3 amazonS3, string bucketName = "attorney-journal-dev") { _bucketName = bucketName; _amazonS3 = amazonS3; _transferUtility = new TransferUtility(_amazonS3); }
public ValuesController(IAmazonS3 amazonS3) { this.amazons3 = amazonS3; }
public BucketRepository(IAmazonS3 client) { _client = client; }
public static void Main() { s3Client = new AmazonS3Client(bucketRegion); string urlString = GeneratePreSignedURL(); }
public S3Service(IAmazonS3 client) { _client = client; }
public Copier(IAmazonS3 s3) { this.s3 = s3; liveBucketName = "live-bucket"; }
private Amazon.S3.Model.PutLifecycleConfigurationResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.PutLifecycleConfigurationRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Storage Service (S3)", "PutLifecycleConfiguration"); try { #if DESKTOP return(client.PutLifecycleConfiguration(request)); #elif CORECLR return(client.PutLifecycleConfigurationAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
protected void Page_Load(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(1024); using (StringWriter sr = new StringWriter(sb)) { try { ec2 = AWSClientFactory.CreateAmazonEC2Client(); this.WriteEC2Info(); } catch (AmazonEC2Exception ex) { if (ex.ErrorCode != null && ex.ErrorCode.Equals("AuthFailure")) { sr.WriteLine("The account you are using is not signed up for Amazon EC2."); sr.WriteLine("<br />"); sr.WriteLine("You can sign up for Amazon EC2 at http://aws.amazon.com/ec2"); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } else { sr.WriteLine("Caught Exception: " + ex.Message); sr.WriteLine("<br />"); sr.WriteLine("Response Status Code: " + ex.StatusCode); sr.WriteLine("<br />"); sr.WriteLine("Error Code: " + ex.ErrorCode); sr.WriteLine("<br />"); sr.WriteLine("Error Type: " + ex.ErrorType); sr.WriteLine("<br />"); sr.WriteLine("Request ID: " + ex.RequestId); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } this.ec2Placeholder.Text = sr.ToString(); } } sb = new StringBuilder(1024); using (StringWriter sr = new StringWriter(sb)) { try { s3 = AWSClientFactory.CreateAmazonS3Client(); this.WriteS3Info(); } catch (AmazonS3Exception ex) { if (ex.ErrorCode != null && (ex.ErrorCode.Equals("InvalidAccessKeyId") || ex.ErrorCode.Equals("InvalidSecurity"))) { sr.WriteLine("The account you are using is not signed up for Amazon S3"); sr.WriteLine("<br />"); sr.WriteLine("You can sign up for Amazon S3 at http://aws.amazon.com/s3"); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } else { sr.WriteLine("Caught Exception: " + ex.Message); sr.WriteLine("<br />"); sr.WriteLine("Response Status Code: " + ex.StatusCode); sr.WriteLine("<br />"); sr.WriteLine("Error Code: " + ex.ErrorCode); sr.WriteLine("<br />"); sr.WriteLine("Request ID: " + ex.RequestId); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } this.s3Placeholder.Text = sr.ToString(); } } sb = new StringBuilder(1024); using (StringWriter sr = new StringWriter(sb)) { try { sdb = AWSClientFactory.CreateAmazonSimpleDBClient(); this.WriteSimpleDBInfo(); } catch (AmazonSimpleDBException ex) { if (ex.ErrorCode != null && ex.ErrorCode.Equals("InvalidClientTokenId")) { sr.WriteLine("The account you are using is not signed up for Amazon SimpleDB."); sr.WriteLine("<br />"); sr.WriteLine("You can sign up for Amazon SimpleDB at http://aws.amazon.com/simpledb"); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } else { sr.WriteLine("Exception Message: " + ex.Message); sr.WriteLine("<br />"); sr.WriteLine("Response Status Code: " + ex.StatusCode); sr.WriteLine("<br />"); sr.WriteLine("Error Code: " + ex.ErrorCode); sr.WriteLine("<br />"); sr.WriteLine("Error Type: " + ex.ErrorType); sr.WriteLine("<br />"); sr.WriteLine("Request ID: " + ex.RequestId); sr.WriteLine("<br />"); sr.WriteLine("<br />"); } this.sdbPlaceholder.Text = sr.ToString(); } } }
/// <summary> /// Constructs an instance with a preconfigured S3 client. This can be used for testing the outside of the Lambda environment. /// </summary> /// <param name="s3Client"></param> public Function(IAmazonS3 s3Client) { this.S3Client = s3Client; }
/// <summary> /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the /// region the Lambda function is executed in. /// </summary> public Function() { S3Client = new AmazonS3Client(); }
public AwsS3Service(Infrastructure.IServiceProvider service) : base(service) { _s3Client = new AmazonS3Client(_accessKeyId, _secretAccessKey, _bucketRegion); }
//--- Constructors --- public S3Bucket(string bucketArn, IAmazonS3 s3Client = null) { BucketName = bucketArn.Split(':').Last() ?? throw new ArgumentNullException(nameof(bucketArn)); _s3Client = s3Client ?? new AmazonS3Client(); }
public S3Repository(IAmazonS3 amazonS3) { _amazonS3 = amazonS3 ?? throw new ArgumentNullException(nameof(amazonS3)); }
public S3ProxyController(IConfiguration configuration, ILogger <S3ProxyController> logger, IAmazonS3 s3Client) { this.Logger = logger; this.S3Client = s3Client; this.BucketName = configuration[Startup.AppS3BucketKey]; if (string.IsNullOrEmpty(this.BucketName)) { logger.LogCritical("Missing configuration for S3 bucket. The AppS3Bucket configuration must be set to a S3 bucket."); throw new Exception("Missing configuration for S3 bucket. The AppS3Bucket configuration must be set to a S3 bucket."); } logger.LogInformation($"Configured to use bucket {this.BucketName}"); }
public Funcs(IConfiguration configuration) { this.configuration = configuration; s3Client = new AmazonS3Client(GetCredentials(), bucketRegion); }
public FileStorageService(FileStorageOptions options) { _bucketName = options.BucketName; _client = new AmazonS3Client(new BasicAWSCredentials(options.AccessKey, options.SecretKey)); }
public S3FileStoreService(IAmazonS3 s3) { amazonS3 = s3; }
public S3Objects(IAmazonS3 client) { s3Client = client; }
public S3StorageManagerTests() { _amazonS3 = Substitute.For <IAmazonS3>(); _loggerFactory = Substitute.For <ILoggerFactory>(); }
public static void ClassInitialize(TestContext testContext) { iamClient = new AmazonIdentityManagementServiceClient(); s3Client = new AmazonS3Client(); }
private async static Task DeleteS3BucketWithObjectsAsync(IAmazonS3 s3Client, string bucketName, CancellationToken cancellationToken = new CancellationToken()) { // Validations. if (s3Client == null) { throw new ArgumentNullException("s3Client", "The s3Client cannot be null!"); } if (string.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException("bucketName", "The bucketName cannot be null or empty string!"); } var listVersionsRequest = new ListVersionsRequest { BucketName = bucketName }; ListVersionsResponse listVersionsResponse; string lastRequestId = null; // Iterate through the objects in the bucket and delete them. do { // Check if the operation has been canceled. cancellationToken.ThrowIfCancellationRequested(); // List all the versions of all the objects in the bucket. listVersionsResponse = await s3Client.ListVersionsAsync(listVersionsRequest); // Silverlight uses HTTP caching, so avoid an infinite loop by throwing an exception if (string.Equals(lastRequestId, listVersionsResponse.ResponseMetadata.RequestId, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(); } lastRequestId = listVersionsResponse.ResponseMetadata.RequestId; if (listVersionsResponse.Versions.Count == 0) { // If the bucket has no objects break the loop. break; } var keyVersionList = new List <KeyVersion>(listVersionsResponse.Versions.Count); for (int index = 0; index < listVersionsResponse.Versions.Count; index++) { keyVersionList.Add(new KeyVersion { Key = listVersionsResponse.Versions[index].Key, VersionId = listVersionsResponse.Versions[index].VersionId }); } try { // Delete the current set of objects. var deleteObjectsResponse = await s3Client.DeleteObjectsAsync(new DeleteObjectsRequest { BucketName = bucketName, Objects = keyVersionList, Quiet = true }); //if (!deleteOptions.QuietMode) //{ // // If quiet mode is not set, update the client with list of deleted objects. // InvokeS3DeleteBucketWithObjectsUpdateCallback( // updateCallback, // new S3DeleteBucketWithObjectsUpdate // { // DeletedObjects = deleteObjectsResponse.DeletedObjects // } // ); //} } catch //(DeleteObjectsException deleteObjectsException) { //if (deleteOptions.ContinueOnError) //{ // // Continue the delete operation if an error was encountered. // // Update the client with the list of objects that were deleted and the // // list of objects on which the delete failed. // InvokeS3DeleteBucketWithObjectsUpdateCallback( // updateCallback, // new S3DeleteBucketWithObjectsUpdate // { // DeletedObjects = deleteObjectsException.Response.DeletedObjects, // DeleteErrors = deleteObjectsException.Response.DeleteErrors // } // ); //} //else //{ // // Re-throw the exception if an error was encountered. // throw; //} throw; } // Set the markers to get next set of objects from the bucket. listVersionsRequest.KeyMarker = listVersionsResponse.NextKeyMarker; listVersionsRequest.VersionIdMarker = listVersionsResponse.NextVersionIdMarker; } // Continue listing objects and deleting them until the bucket is empty. while (listVersionsResponse.IsTruncated); const int maxRetries = 10; for (int retries = 1; retries <= maxRetries; retries++) { try { // Bucket is empty, delete the bucket. await s3Client.DeleteBucketAsync(new DeleteBucketRequest { BucketName = bucketName }); break; } catch (AmazonS3Exception e) { if (e.StatusCode != HttpStatusCode.Conflict || retries == maxRetries) { throw; } else { DefaultRetryPolicy.WaitBeforeRetry(retries, 5000); } } } //// Signal that the operation is completed. //asyncCancelableResult.SignalWaitHandleOnCompleted(); }
//--- Methods --- public override async Task InitializeAsync(LambdaConfig config) { // Initialize AWS clients _dynamoDbClient = new AmazonDynamoDBClient(); _s3Client = new AmazonS3Client(); }
public static Task DeleteBucketWithObjectsAsync(IAmazonS3 s3Client, string bucketName) { return(DeleteS3BucketWithObjectsAsync(s3Client, bucketName)); }
static void Main(string[] args) { client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKeyId, bucketRegion); ReadObjectData().Wait(); }
public static void Main(string[] args) { s3Client = new AmazonS3Client(bucketRegion); GetObjectListWithAllVersionsAsync().Wait(); }
public S3Store(IConfigurationProvider configurationProvider) { _client = CreateClient(GetSettings(configurationProvider)); }
public S3Store(IAmazonS3 amazonS3Client) { _client = amazonS3Client; }