我正在尝试使需要在AWS上托管的Pod上产生负载的方案自动化。他们需要使用“ AWS签名版本4”进行身份验证。
我不确定如何通过加特林发送“ AWS签名版本4”的请求。AWS Signature版本4采用这些值。
返回
"X-Amz-Date":
"Authorization": "AWS4-HMAC-SHA256 Credential=AccessKey/us-east-1/apigateway/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature="somevalue",
提供所有这样的值会有所帮助吗?
.exec(http("RESTGetOAuthToken")
.post("")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Content-Type", "application/json")
.header("X-Amz-Date", "")
.header("Authorization", "")
.header("Cache-Control", "no-cache")
.body(StringBody("""{
"orders": [
]
}
]
您需要生成X-Amz-日期和授权详细信息,并将其与标头一起传递。您可以使用下面的类来提取这两个信息。
[https://github.com/sandipperf/AWS_API_Request_Gatling/blob/master/RequestSigner.scala通过提供ASWAccessKey和AWSSecretKey提取AWS签名密钥。
**这是导入RequestSigner类**之后如何从scala测试类中提取信息的方法
/ ** ********************************************* ******生成AWS Signature密钥************************************** /val AwsAccessKey =“ XXXXXXXXXXXX”val AwsSecretKey =“ XXXXXXXXXXXXXXXXXXXXXXXX”
val signature = RequestSigner.sign(
uriPath = "/Your/URL/HERE",
method = "POST",
//body = Some("""{ "hello": "foo" }"""),
body = Some(requestBuildBody),
//您需要传递requestBuildBody i.eyour您将与postrequest一起传递的实际请求正文
headers = Seq(("Host", List("XXXXXXXX.execute-api.us-XXXX-2.amazonaws.com"))),
queryParameters = Seq.empty,
credentials = new BasicAWSCredentials(AwsAccessKey, AwsSecretKey),
region = "us-XXXX-2",
service = "execute-api")
val amzStamp = (signature.toString).substring(18, 34)
val sign = (signature.toString).substring(35, 223)
AmazonTimeDetails.append(amzStamp).toString
SignatureDetails.append(sign).toString
从上面的代码中,您将获得X-Amz-Date和signatureDetails,需要在标头中使用
"Host" -> "XXXXXX.execute-api.us-XXXX-X.amazonaws.com",
"Content-Type" -> "application/json",
"X-Amz-Date" -> "${amazonTimeDetails}",
"Authorization" -> "${signatureDetails}")