【以下的问题经过翻译处理】 你好,
我之前通过编号为12004513771的支持提交了一个问题,但是他们无法为我解决一个自定义代码问题。
我想在Typescript中复制S3 MRAP签名,基于这篇文章:
https://aws.amazon.com/blogs/storage/building-an-active-active-latency-based-application-across-multiple-regions/
我遇到的具体问题是,在AWS SDK for node ‘aws-crt’ 1.15.9和nodejs16.x中:
import { auth } from 'aws-crt';
import { HttpHeaders, HttpRequest } from "aws-crt/dist/native/http";
.....
const httpRequest = new HttpRequest(method, endpoint, headers);
const signedHttpRequest: HttpRequest = await auth.aws_sign_request(httpRequest, config);
但是我遇到的问题是上述两个调用都返回一个空对象{}
Typescript代码:
签名函数:
async function sigV4ASignBasic(method: string, endpoint: string, headers: HttpHeaders, service: string): Promise<HttpHeaders> {
const httpRequest = new HttpRequest(method, endpoint, headers);
console.log('httpRequest: ' + JSON.stringify(httpRequest))
const config: AwsSigningConfig = {
service: service,
region: "*",
algorithm: auth.AwsSigningAlgorithm.SigV4Asymmetric,
signature_type: auth.AwsSignatureType.HttpRequestViaHeaders,
signed_body_header: auth.AwsSignedBodyHeaderType.XAmzContentSha256,
provider: auth.AwsCredentialsProvider.newDefault()
};
console.log('config: ' + JSON.stringify(config))
const signedHttpRequest: HttpRequest = await auth.aws_sign_request(httpRequest, config);
console.log('signedHttpRequest: ' + JSON.stringify(signedHttpRequest))
return signedHttpRequest.headers;
}
从中调用:
console.log('method: %s, endpoint: %s, cfReadOnlyHeaders with X-Amz-Cf-Id: %s, service: %s', method, endpoint, JSON.stringify(cfReadOnlyHeaders), service)
// # Sign the request with Signature Version 4A (SigV4A).
const authHeaders: HttpHeaders = await sigV4ASignBasic(method, endpoint, cfReadOnlyHeaders, service)
以上日志:
2023-02-14T10:58:06.610Z 4b78c29a-a348-4415-bf7b-533bb4cc0734 INFO method: GET, endpoint: https://xxxxxxxxxxxx.mrap.accesspoint.s3-global.amazonaws.com/favicon.ico, cfReadOnlyHeaders with X-Amz-Cf-Id: { "X-Amz-Cf-Id": "LTMHFCMnnmxohWwJpJHoUNfWR0_gZtk_9InF14ToRrKjpWtjwDiPlA==" } , service: s3