I'm trying to get a file from an S3 bucket as part of the Setup Thread Group for a JMeter test, and I have the following Groovy script in a JSR223 Sampler:
import java.io.IOException
import java.io.InputStream
import java.util.Properties
import com.amazonaws.services.s3.AmazonS3
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.GetObjectRequest
import com.amazonaws.services.s3.model.S3Object
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.services.s3.S3CredentialsProviderChain
def awsAccessKey = "my_key"
def awsSecretAccessKey = "my_secret_key"
System.setProperty("aws.accessKeyId", awsAccessKey)
System.setProperty("aws.secretKey", awsSecretAccessKey)
def awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretAccessKey)
def s3Client = AmazonS3ClientBuilder.standard()
.withRegion("us-west-2")
.build()
def s3Object = s3Client.getObject(new GetObjectRequest("bucket-name", "filename"))
def is = s3Object.getObjectContent()
The code throws the following, both when I use .withCredentials(awsCreds) and when I set the system properties:
java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.services.s3.S3CredentialsProviderChain
I've also converted the same code to the following Beanshell Sampler:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.auth.BasicAWSCredentials;
String awsAccessKey = "my_key";
String awsSecretAccessKey = "my_secret_key";
System.setProperty("aws.accessKeyId", awsAccessKey);
System.setProperty("aws.secretKey", awsSecretAccessKey);
BasicAWSCredentials awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretAccessKey);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion("us-west-2").build();
S3Object s3Object = s3Client.getObject(new GetObjectRequest("bucket-name", "filename"));
InputStream is = s3Object.getObjectContent();
However, this results in the following:
org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval
Sourced file: inline evaluation of: ``import java.io.IOException; import java.io.InputStream; import java.util.Propert . . . '' : Typed variable declaration : Method Invocation AmazonS3ClientBuilder.standard
When I put this same code into a test Java class, it runs with no issues. I have aws-java-sdk-1.11.160.jar and aws-java-sdk-core-1.11.160.jar in my jmeter/lib, so I don't believe it's a missing dependency. Am I missing something else?