У меня есть лямбда-функция AWS с использованием Node.js 12.x. Вот мой код:
exports.handler = async function(event, context) {
const https = require('https');
const sheetId = 01234;
const testData = JSON.stringify({"toTop":true, "cells": [ {"columnId": 3148210723153796, "value": 'TEST'} ] });
const options = {
hostname: 'api.website.com',
port: 443,
path: `/logs`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer oefohjeoiefoijn'
}
};
const req = https.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.');
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});
// Write data to request body
req.write(testData);
req.end();
}
Запрос не выполняется. Я не получаю ошибок в Cloudwatch. Точный код (с удаленным экспортом обработчика) отлично работает в Node.js 12.x на моей машине.