Best way to move files between S3 buckets?

前端 未结 12 2130
暗喜
暗喜 2020-12-07 11:09

I\'d like to copy some files from a production bucket to a development bucket daily.

For example: Copy productionbucket/feed/feedname/date to developmentbucket/feed/

12条回答
  •  孤城傲影
    2020-12-07 11:31

    .NET Example as requested:

    using (client)
    {
        var existingObject = client.ListObjects(requestForExisingFile).S3Objects; 
        if (existingObject.Count == 1)
        {
            var requestCopyObject = new CopyObjectRequest()
            {
                SourceBucket = BucketNameProd,
                SourceKey = objectToMerge.Key,
                DestinationBucket = BucketNameDev,
                DestinationKey = newKey
            };
            client.CopyObject(requestCopyObject);
        }
    }
    

    with client being something like

    var config = new AmazonS3Config { CommunicationProtocol = Protocol.HTTP, ServiceURL = "s3-eu-west-1.amazonaws.com" };
    var client = AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretAccessKey, config);
    

    There might be a better way, but it's just some quick code I wrote to get some files transferred.

提交回复
热议问题