我正在尝试自动化一个场景,该场景需要在AWS上托管的Pod上生成负载。他们需要使用“ AWS签名版本4”进行身份验证。 我不确定如何通过加特林发送“ AWS签名版本4”的请求 AWS Signature版本4采用这些值。 1.)AccessKey 2.)SecretKey 3.)AWS地区 4.)服务名称 退货 “ X-Amz-Date”: “授权”:“ AWS4-HMAC-SHA256凭据= 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": [
]
}
]
答案 0 :(得分:0)
您需要生成X-Amz-日期和授权详细信息,并将其与标头一起传递。您可以使用下面的类来提取这两个信息。
https://github.com/sandipperf/AWS_API_Request_Gatling/blob/master/RequestSigner.scala通过提供ASWAccessKey和AWSSecretKey提取AWS签名密钥。
**这是在导入RequestSigner类**之后从scala测试类中提取信息的方法
val AwsAccessKey = "XXXXXXXXXXXX"
val AwsSecretKey = "XXXXXXXXXXXXXXXXXXXXXXXX"
val signature = RequestSigner.sign(
uriPath = "/Your/URL/HERE",
method = "POST",
//body = Some("""{ "hello": "foo" }"""),
body = Some(requestBuildBody),
//requestBuildBody = your actual request body you are going to pass along with post request
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}")