aws проблема POST-метода API -api-gateway-client - PullRequest
0 голосов
/ 27 апреля 2020

Мы используем aws-api-gateway-client для исполнения всех aws -рест API. Приведенный ниже код работал нормально, пока мы не обновили наш сервер с window 2008 до window 2016.

. На новом Windows Server 2016 ниже приведенный код прекрасно работает для GET / Delete методов, но для POST метод не работает. Ниже приведена ошибка ответа.

Версия пакета Windows 2016 - aws-api-gateway-client@0.3.3

Версия пакета Windows 2008 - aws-api-gateway-client@0.2.16

У всех, кто сталкивался с подобной проблемой после обновления ?

/* ****************************************************************************************************************************************************************************
API NAME : Invoke AWS REST API using node js
Library Used: aws-api-gateway-client
Date : 1/18/2019
Owner: #######
******************************************************************************************************************************************************************************** */

var apigClientFactory = require('aws-api-gateway-client').default;
process.argv.splice(0, 2)
let command = JSON.parse(process.argv.join(" ").split('\\').join('') || '{}');

var output = {};
process.on("exit", function() {
    printOutput();
});

var apigClient = apigClientFactory.newClient({
    invokeUrl: command.endpoint, // REQUIRED
    accessKey: command.access_key, // REQUIRED
    secretKey: command.secret_key, // REQUIRED
    region: command.region, // REQUIRED: The region where the AapiKeyloyed.
    retries: 4,
    retryCondition: (err) => { // OPTIONAL: Callback to further control if request should be retried.  Uses axon-retry plugin.
        return err.response && err.response.status === 500;
    }
});

var pathParams = command.pathParams;
var pathTemplate = command.pathTemplate; // '/api/v1/sites'
var method = command.method; // 'POST';
var additionalParams = command.additionalParams; //queryParams & Headers if any

var body = command.body;

apigClient.invokeApi(pathParams, pathTemplate, method, additionalParams, body)
    .then(function(result) {
        var statuscode = result.status;
        var statustext = result.statusText;
        var job_id = result.headers['location'];
        var responseBody = result.data;
        output.statuscode = statuscode,
            output.statustext = statustext,
            output.job_id = job_id,
            output.responseBody = responseBody;
        //output.result = result;

    }).catch(function(error) {
        if (error.response != undefined) {
            var statuscode = error.response.status;
            var statustext = error.response.statusText;
            var responseBody = error.response.data;
            output.statuscode = statuscode,
                output.statustext = statustext,
                output.responseBody = responseBody;
            //output.response = error;
        } else {
            var statuscode = error.code;
            var statustext = error.errno;
            output.statuscode = statuscode;
            output.statustext = statustext;
            //output.error = error;
        }
    });


function printOutput() {
    console.log(JSON.stringify(output));
}

Ошибка ответа

{"statuscode":403,"statustext":"Forbidden","responseBody":{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\n\nThe Canonical String for this request should have been\n'POST\n<>\n"}}

1 Ответ

0 голосов
/ 27 апреля 2020

Я удалил aws-api-gateway-client@0.3.3 и установил рабочую версию NPM модуля

>npm install aws-api-gateway-client@0.2.16
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...