【问题标题】:Jmeter-How to copy files from one AWS S3 bucket to another bucket?Jmeter-如何将文件从一个 AWS S3 存储桶复制到另一个存储桶?
【发布时间】:2021-01-04 10:36:58
【问题描述】:

我将 tar.zip 文件放在 AWS S3 位置的 newbucket 中。我有脚本可以剪切文件并将其放在另一个 S3 存储桶中。每次我需要将文件从本地上传到 newbucket 作为 JSSR 预处理器以从本地上传文件。我可以将 S3 中的文件从一个存储桶复制粘贴到另一个存储桶吗?

【问题讨论】:

    标签: amazon-s3 jmeter


    【解决方案1】:

    我认为“官方”的方式是一般使用AWS CLIaws s3 sync command in particular

    aws s3 sync s3://DOC-EXAMPLE-BUCKET-SOURCE s3://DOC-EXAMPLE-BUCKET-TARGET
    

    可以从 JSR223 Sampler 或 OS Process Sampler 启动该命令

    如果您更喜欢以编程方式执行此操作 - 请查看 Copy an Object Using the AWS SDK for Java 文章,代码 sn-p 以防万一:

    import com.amazonaws.AmazonServiceException;
    import com.amazonaws.SdkClientException;
    import com.amazonaws.auth.profile.ProfileCredentialsProvider;
    import com.amazonaws.regions.Regions;
    import com.amazonaws.services.s3.AmazonS3;
    import com.amazonaws.services.s3.AmazonS3ClientBuilder;
    import com.amazonaws.services.s3.model.CopyObjectRequest;
    
    import java.io.IOException;
    
    public class CopyObjectSingleOperation {
    
        public static void main(String[] args) throws IOException {
            Regions clientRegion = Regions.DEFAULT_REGION;
            String bucketName = "*** Bucket name ***";
            String sourceKey = "*** Source object key *** ";
            String destinationKey = "*** Destination object key ***";
    
            try {
                AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                        .withCredentials(new ProfileCredentialsProvider())
                        .withRegion(clientRegion)
                        .build();
    
                // Copy the object into a new object in the same bucket.
                CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucketName, sourceKey, bucketName, destinationKey);
                s3Client.copyObject(copyObjRequest);
            } catch (AmazonServiceException e) {
                // The call was transmitted successfully, but Amazon S3 couldn't process 
                // it, so it returned an error response.
                e.printStackTrace();
            } catch (SdkClientException e) {
                // Amazon S3 couldn't be contacted for a response, or the client  
                // couldn't parse the response from Amazon S3.
                e.printStackTrace();
            }
        }
    }
    

    【讨论】:

    • 通过使用上面的代码,我最多可以复制 5 GB 大小的文件,我如何将超过 5 GB 大小的文件从一个 S3 存储桶复制到另一个 S3 存储桶,例如我必须复制 10 GB 大小文件从一个 s3 存储桶到另一个 s3 存储桶,如何复制?
    猜你喜欢
    • 1970-01-01
    • 2018-11-22
    • 2023-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2013-11-01
    • 2020-05-29
    相关资源
    最近更新 更多