Skip to content

Instantly share code, notes, and snippets.

@nobel6018
Last active May 24, 2022 00:08
Show Gist options
  • Save nobel6018/514432f8ee062193ea16ffcfcdbd472b to your computer and use it in GitHub Desktop.
Save nobel6018/514432f8ee062193ea16ffcfcdbd472b to your computer and use it in GitHub Desktop.
AWS Lambda POST 요청, Javascript, https is pre-built library (no image needs)
const https = require('https');
exports.handler = async (event) => {
console.log("event: ", event);
const options = {
hostname: "gist.github.com", // replace correctly
port: 443,
path: '/v1/articles', // replace correctly
method: 'POST',
headers: {
"Content-Type": "application/json"
},
};
// event is json format: {"title": "fancy title", "content: "fancy content..."}
// replace it correctly
const dataString = JSON.stringify(event);
const promise = new Promise(function (resolve, reject) {
const req = https.request(options, (res) => {
res.setEncoding("utf-8");
let body = '';
res.on('data', chunk => {
body += chunk;
});
res.on('end', () => resolve(body))
}).on('error', (e) => {
reject(Error(e))
})
req.write(dataString);
req.end();
}
)
return promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment