var apigClient = apigClientFactory.newClient({
accessKey: AWSCognito.config.credentials.accessKeyId,
secretKey: AWSCognito.config.credentials.secretAccessKey,
sessionToken: AWSCognito.config.credentials.sessionToken
});
var params = {
// This is where any modeled request parameters should be added.
// The key is the parameter name, as it is defined in the API in API Gateway.
};
var body = {};
var additionalParams = {
// If there are any unmodeled query parameters or headers that must be
// sent with the request, add them here.
headers: {
'Content-Type': 'application/json'
},
queryParams: {}
};
apigClient.<resource><Method>(params, body, additionalParams)
.then(function(result) {
//
}).catch(function(err) {
//
});
1 回答
由于您希望首先通过经过身份验证的Cognito身份调用API
修改身份池的auth角色以具有api执行策略,您可以将托管策略"AmazonAPIGatewayInvokeFullAccess"附加到相应的角色
在相应方法请求下的API网关中,将授权添加为"AWS_IAM"
您需要在使用"IAM" auth时签署请求,在此解释https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html
您可以从API网关的舞台面板生成并下载SDK,而不是#3,并通过sdk调用api .
获得认知会话后,您可以使用下面的sdk拨打电话