コード例 #1
0
ファイル: S3.cs プロジェクト: TcmExtensions/S3ECLProvider
        internal S3(string region, string bucketName, string accessKeyId, string secretAccessKey, string bucketUrl, string prefix)
        {
            if (String.IsNullOrEmpty(region))
            {
                throw new ArgumentNullException("S3 Region not specified.");
            }

            if (String.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentNullException("S3 BucketName not specified.");
            }

            if (String.IsNullOrEmpty(accessKeyId))
            {
                throw new ArgumentNullException("S3 AccessKeyId not specified.");
            }

            if (String.IsNullOrEmpty(secretAccessKey))
            {
                throw new ArgumentNullException("S3 SecretAccessKey not specified.");
            }

            if (String.IsNullOrEmpty(bucketUrl))
            {
                throw new ArgumentNullException("S3 BucketUrl not specified.");
            }

            _bucketName = bucketName;
            _bucketUrl  = bucketUrl;

            if (!String.IsNullOrEmpty(prefix))
            {
                _prefix = prefix;
            }
            else
            {
                _prefix = String.Empty;
            }

            Amazon.RegionEndpoint regionEndpoint = Amazon.RegionEndpoint.GetBySystemName(region);

            if (regionEndpoint == null)
            {
                throw new ArgumentException(String.Format("Unknown S3 region: \"{0}\".", region), "region");
            }

            _S3Client = new AmazonS3Client(accessKeyId, secretAccessKey, regionEndpoint);

            if (!_S3Client.DoesS3BucketExist(bucketName))
            {
                throw new ArgumentException(String.Format("S3 bucket \"{0}\" does not exist or is not accessible.", bucketName), "bucketName");
            }
        }
コード例 #2
0
        async Task CreateABucketAsync(string bucketToCreate, bool isPublic = true)
        {
            await CarryOutAWSTask(async() =>
            {
                if (client.DoesS3BucketExist(bucketToCreate))
                {
                    Console.WriteLine($"{bucketToCreate} already exists, skipping this step");
                }

                PutBucketRequest putBucketRequest = new PutBucketRequest()
                {
                    BucketName   = bucketToCreate,
                    BucketRegion = S3Region.EUW2,
                    CannedACL    = isPublic ? S3CannedACL.PublicRead : S3CannedACL.Private
                };
                var response = await client.PutBucketAsync(putBucketRequest);
            }, "Create a bucket");
        }