You should sign your request and credentials as per AWS Signature V4.
签名示例代码可用@
https://s3.amazonaws.com/aws-java-sdk/samples/AWSS3SigV4JavaSamples.jar
Sample code :
URL url = new URL("https://XXXXXXX.execute-api.us-west-2.amazonaws.com/dev/pets");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
conn.setRequestProperty("host", "XXXXXXXXXX.execute-api.us-west-2.amazonaws.com");
Map<String, String> headers = new HashMap<String, String>();
headers.put("x-amz-content-sha256", AWS4SignerBase.EMPTY_BODY_SHA256);
headers.put("X-Amz-Security-Token", "XXXXXX+XXXXXXXXXXXXXXX/5N+XXXXXXXXX/XXXXX/XXXXXX/XXXXXXXX/XXXXXXXX=");
AWS4SignerForAuthorizationHeader signer = new AWS4SignerForAuthorizationHeader(
url, "GET", "execute-api", "us-west-2");
String authorization = signer.computeSignature(headers,
null, // no query parameters
AWS4SignerBase.EMPTY_BODY_SHA256,
"XXXXXX",
"S+XXXXXX+XXXXXX/XXXX");
headers.put("Authorization", authorization);
String response = HttpUtils.invokeHttpRequest(url, "GET", headers, null);