in lambdas/static-asset-uploader/build/apigateway-js-sdk/lib/apiGatewayCore/sigV4Client.js [141:212]
awsSigV4Client.makeRequest = function (request) {
var verb = apiGateway.core.utils.assertDefined(request.verb, 'verb');
var path = apiGateway.core.utils.assertDefined(request.path, 'path');
var queryParams = apiGateway.core.utils.copy(request.queryParams);
if (queryParams === undefined) {
queryParams = {};
}
var headers = apiGateway.core.utils.copy(request.headers);
if (headers === undefined) {
headers = {};
}
//If the user has not specified an override for Content type the use default
if(headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
//If the user has not specified an override for Accept type the use default
if(headers['Accept'] === undefined) {
headers['Accept'] = config.defaultAcceptType;
}
var body = apiGateway.core.utils.copy(request.body);
if (body === undefined || verb === 'GET') { // override request body and set to empty when signing GET requests
body = '';
} else {
body = JSON.stringify(body);
}
//If there is no body remove the content-type header so it is not included in SigV4 calculation
if(body === '' || body === undefined || body === null) {
delete headers['Content-Type'];
}
var datetime = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z').replace(/[:\-]|\.\d{3}/g, '');
headers[X_AMZ_DATE] = datetime;
var parser = document.createElement('a');
parser.href = awsSigV4Client.endpoint;
headers[HOST] = parser.hostname;
var canonicalRequest = buildCanonicalRequest(verb, path, queryParams, headers, body);
var hashedCanonicalRequest = hashCanonicalRequest(canonicalRequest);
var credentialScope = buildCredentialScope(datetime, awsSigV4Client.region, awsSigV4Client.serviceName);
var stringToSign = buildStringToSign(datetime, credentialScope, hashedCanonicalRequest);
var signingKey = calculateSigningKey(awsSigV4Client.secretKey, datetime, awsSigV4Client.region, awsSigV4Client.serviceName);
var signature = calculateSignature(signingKey, stringToSign);
headers[AUTHORIZATION] = buildAuthorizationHeader(awsSigV4Client.accessKey, credentialScope, headers, signature);
if(awsSigV4Client.sessionToken !== undefined && awsSigV4Client.sessionToken !== '') {
headers[X_AMZ_SECURITY_TOKEN] = awsSigV4Client.sessionToken;
}
delete headers[HOST];
var url = config.endpoint + path;
var queryString = buildCanonicalQueryString(queryParams);
if (queryString != '') {
url += '?' + queryString;
}
//Need to re-attach Content-Type if it is not specified at this point
if(headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
var signedRequest = {
method: verb,
url: url,
headers: headers,
data: body,
...request.config
};
return axios(signedRequest);
};