コード例 #1
0
 public AWSClass()
 {
     if (clients3 == null)
         clients3 = new AmazonS3Client(Amazon.RegionEndpoint.USWest2);
     if(clientsns == null)
         clientsns = new AmazonSimpleNotificationServiceClient();
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
ファイル: AlbumCacheTask.cs プロジェクト: alanedwardes/aeblog
 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;
 }
コード例 #4
0
 public BloomS3Client(string bucketName)
 {
     _bucketName = bucketName;
     _amazonS3 = AWSClientFactory.CreateAmazonS3Client(KeyManager.S3AccessKey,
         KeyManager.S3SecretAccessKey, new AmazonS3Config { ServiceURL = "https://s3.amazonaws.com" });
     _transferUtility = new TransferUtility(_amazonS3);
 }
コード例 #5
0
		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;
        }
コード例 #6
0
 internal SimpleUploadCommand(IAmazonS3 s3Client, TransferUtilityConfig config, TransferUtilityUploadRequest fileTransporterRequest)
 {
     this._s3Client = s3Client;
     this._config = config;
     this._fileTransporterRequest = fileTransporterRequest;
     var fileName = fileTransporterRequest.FilePath;
 }
コード例 #7
0
ファイル: S3PutBase.cs プロジェクト: henricj/AwsDedupSync
        protected S3PutBase(IAmazonS3 amazonS3)
        {
            if (null == amazonS3)
                throw new ArgumentNullException(nameof(amazonS3));

            AmazonS3 = amazonS3;
        }
コード例 #8
0
 internal AbortMultipartUploadsCommand(IAmazonS3 s3Client, string bucketName, DateTime initiateDate, TransferUtilityConfig config)
 {
     this._s3Client = s3Client;
     this._bucketName = bucketName;
     this._initiatedDate = initiateDate;
     this._config = config;
 }
コード例 #9
0
        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;
        }
コード例 #10
0
 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;
 }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
ファイル: AmazonS3HttpUtil.cs プロジェクト: aws/aws-sdk-net
 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;
 }
コード例 #13
0
		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;
        }
コード例 #14
0
 public S3VirtualPathProvider(IAmazonS3 client, string bucketName, IAppHost appHost)
     : base(appHost)
 {
     this.AmazonS3 = client;
     this.BucketName = bucketName;
     this.rootDirectory = new S3VirtualDirectory(this, null);
 }
コード例 #15
0
        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();
        }
コード例 #16
0
ファイル: AwsManager.cs プロジェクト: henricj/AwsDedupSync
        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);
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
ファイル: AlbumCacheTask.cs プロジェクト: alanedwardes/aeblog
        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;
        }
コード例 #19
0
 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;
 }
コード例 #20
0
 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);
 }
コード例 #21
0
        /// <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;
                }
            }
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: PMInova/RDSDump
        static void CreateABucket(IAmazonS3 client, string bucketName)
        {
            PutBucketRequest putRequest1 = new PutBucketRequest
            {
                BucketName = bucketName,
                UseClientRegion = true
            };

            PutBucketResponse response1 = client.PutBucket(putRequest1);
        }
コード例 #23
0
        /// <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);
        }
コード例 #24
0
ファイル: S3FileStorage.cs プロジェクト: aduggleby/dragon
 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);
 }
コード例 #25
0
ファイル: S3Links.cs プロジェクト: henricj/AwsDedupSync
        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;
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: MazinZ/hackNY
 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);
 }
コード例 #27
0
ファイル: Program.cs プロジェクト: PMInova/RDSDump
 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;
 }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        public void Dispose()
        {
            if (s3Client == null)
                return;

            try
            {
                s3Client.Dispose();
                s3Client = null;
            }
            catch { }
        }
コード例 #31
0
 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;
 }
コード例 #33
0
 public ExtractDownloads(IAmazonS3 s3Client, DownloadConfiguration config)
 {
     _client = s3Client;
     _config = config;
 }
コード例 #34
0
ファイル: AmazonS3Helper.cs プロジェクト: rj-sh17/attroney
 /// <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);
 }
コード例 #35
0
 public ValuesController(IAmazonS3 amazonS3)
 {
     this.amazons3 = amazonS3;
 }
コード例 #36
0
 public BucketRepository(IAmazonS3 client)
 {
     _client = client;
 }
コード例 #37
0
 public static void Main()
 {
     s3Client = new AmazonS3Client(bucketRegion);
     string urlString = GeneratePreSignedURL();
 }
コード例 #38
0
 public S3Service(IAmazonS3 client)
 {
     _client = client;
 }
コード例 #39
0
        public Copier(IAmazonS3 s3)
        {
            this.s3 = s3;

            liveBucketName = "live-bucket";
        }
コード例 #40
0
 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;
     }
 }
コード例 #41
0
ファイル: Default.aspx.cs プロジェクト: teintinu/mar-net-ram
        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();
                }
            }
        }
コード例 #42
0
 /// <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;
 }
コード例 #43
0
 /// <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();
 }
コード例 #44
0
 public AwsS3Service(Infrastructure.IServiceProvider service) : base(service)
 {
     _s3Client = new AmazonS3Client(_accessKeyId, _secretAccessKey, _bucketRegion);
 }
コード例 #45
0
 //--- Constructors ---
 public S3Bucket(string bucketArn, IAmazonS3 s3Client = null)
 {
     BucketName = bucketArn.Split(':').Last() ?? throw new ArgumentNullException(nameof(bucketArn));
     _s3Client  = s3Client ?? new AmazonS3Client();
 }
コード例 #46
0
 public S3Repository(IAmazonS3 amazonS3)
 {
     _amazonS3 = amazonS3 ?? throw new ArgumentNullException(nameof(amazonS3));
 }
コード例 #47
0
        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}");
        }
コード例 #48
0
 public Funcs(IConfiguration configuration)
 {
     this.configuration = configuration;
     s3Client           = new AmazonS3Client(GetCredentials(), bucketRegion);
 }
コード例 #49
0
 public FileStorageService(FileStorageOptions options)
 {
     _bucketName = options.BucketName;
     _client     = new AmazonS3Client(new BasicAWSCredentials(options.AccessKey, options.SecretKey));
 }
コード例 #50
0
 public S3FileStoreService(IAmazonS3 s3)
 {
     amazonS3 = s3;
 }
コード例 #51
0
 public S3Objects(IAmazonS3 client)
 {
     s3Client = client;
 }
コード例 #52
0
        public S3StorageManagerTests()
        {
            _amazonS3 = Substitute.For <IAmazonS3>();

            _loggerFactory = Substitute.For <ILoggerFactory>();
        }
コード例 #53
0
 public static void ClassInitialize(TestContext testContext)
 {
     iamClient = new AmazonIdentityManagementServiceClient();
     s3Client  = new AmazonS3Client();
 }
コード例 #54
0
        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();
        }
コード例 #55
0
 //--- Methods ---
 public override async Task InitializeAsync(LambdaConfig config)
 {
     // Initialize AWS clients
     _dynamoDbClient = new AmazonDynamoDBClient();
     _s3Client       = new AmazonS3Client();
 }
コード例 #56
0
 public static Task DeleteBucketWithObjectsAsync(IAmazonS3 s3Client, string bucketName)
 {
     return(DeleteS3BucketWithObjectsAsync(s3Client, bucketName));
 }
コード例 #57
0
 static void Main(string[] args)
 {
     client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKeyId, bucketRegion);
     ReadObjectData().Wait();
 }
コード例 #58
0
 public static void Main(string[] args)
 {
     s3Client = new AmazonS3Client(bucketRegion);
     GetObjectListWithAllVersionsAsync().Wait();
 }
コード例 #59
0
 public S3Store(IConfigurationProvider configurationProvider)
 {
     _client = CreateClient(GetSettings(configurationProvider));
 }
コード例 #60
0
 public S3Store(IAmazonS3 amazonS3Client)
 {
     _client = amazonS3Client;
 }