Jmeter-如何将文件从一个AWS S3存储桶复制到另一个存储桶?
我将tar.zip文件放置在AWS S3位置的newbucket中.我有脚本将剪切文件并将其放置在另一个S3存储桶中.每次我需要将本地文件作为JSSR预处理程序从本地上传到newbucket时,都需要从本地上传文件.我可以将S3中的文件粘贴从一个存储桶复制到另一个存储桶吗?
I have tar.zip files placed in newbucket of AWS S3 location. I have script which will cut the file and place it in another S3 bucket. Every time I need to upload the files from local to newbucket as JSSR preprocessor to upload the files from local. Can I do copy paste of file in S3 from one bucket to another bucket ?
我认为正式"方式是一般使用 AWS CLI 和
I think the "official" way is to use AWS CLI in general and aws s3 sync
command in particular:
aws s3 sync s3://DOC-EXAMPLE-BUCKET-SOURCE s3://DOC-EXAMPLE-BUCKET-TARGET
The command can be kicked off either from JSR223 Sampler or from the OS Process Sampler
如果您喜欢通过编程方式执行此操作,请查看使用以下对象复制对象适用于Java的AWS开发工具包一文,以防万一:
If you prefer doing this programmatically - check out Copy an Object Using the AWS SDK for Java article, the code snippet just in case:
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();
}
}
}