I'm trying to generate a signed AWS request in JMeter.
My first attempt was to put the same parameters, that work fine in my Postman requests, inside an HTTP Header Manager. Those parameters were "AccessKey", "SecretKey", "AWS Region", "Service Name" and "Session Token" but the response said "Access denied". In a best case scenario, I just used the wrong names in this step and renaming them already fixes everything.
My second attempt was to follow the AWS documentation and write a Java class that generates the signed request. Then I wanted to use a JSR223 PreProcessor to set the variables using vars.put. How can I do this correctly? I'm new to JMeter and thought that I might be able to paste my Java code, add the vars.put statement and that's it. But sadly this doesn't create a variable called "aaauthorization" if I run a Debug Sampler afterwards:
class aws_request {
public static String bytesToHex(byte[] hash) {
...
return hexString.toString();
}
private static byte[] HmacSHA256(String data, byte[] key) throws Exception {
...
return mac.doFinal(data.getBytes("UTF8"));
}
private static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName)
throws Exception {
...
return kSigning;
}
public static String getAuthorization() {
try {...
return authorization;
} catch (Exception e) {
return "failed";
}
}
public static void main(String args[]) {
vars.put("aaauthorization", getAuthorization());
}
}
Thank you in advance for your help!