[英]How to send gatling request with AWS Signature Version 4?
I am trying to automate a scenario where I need to generate load on Pods which are hosted on AWS.我正在尝试自动化一个场景,我需要在 AWS 上托管的 Pod 上生成负载。 They require authentication with "AWS Signature Version 4".
它们需要使用“AWS 签名版本 4”进行身份验证。
I am not sure how to send a request with "AWS Signature Version 4" via Gatling.我不确定如何通过 Gatling 发送带有“AWS 签名版本 4”的请求。 AWS Signature Version 4 takes these values.
AWS 签名版本 4 采用这些值。
Returns退货
"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",
Does giving all the values like this will help?提供这样的所有值会有所帮助吗?
.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": [
]
}
]
You need to generate X-Amz-Date and Authorization details and pass them along with the header.您需要生成 X-Amz-Date 和授权详细信息并将它们与标题一起传递。 You can use the below class to extract this two information.
您可以使用下面的类来提取这两个信息。
https://github.com/sandipperf/AWS_API_Request_Gatling/blob/master/RequestSigner.scala to extract AWS signature key by providing ASWAccessKey and AWSSecretKey. https://github.com/sandipperf/AWS_API_Request_Gatling/blob/master/RequestSigner.scala通过提供 ASWAccessKey 和 AWSSecretKey 来提取 AWS 签名密钥。
**Here is how you can extract information from your scala test class after importing RequestSigner class ** **这是在导入 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
From above code you will get X-Amz-Date and signatureDetails , which you need to use in header从上面的代码中,您将获得 X-Amz-Date 和 signatureDetails ,您需要在标题中使用它们
"Host" -> "XXXXXX.execute-api.us-XXXX-X.amazonaws.com",
"Content-Type" -> "application/json",
"X-Amz-Date" -> "${amazonTimeDetails}",
"Authorization" -> "${signatureDetails}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.