Last active
May 24, 2022 00:08
-
-
Save nobel6018/514432f8ee062193ea16ffcfcdbd472b to your computer and use it in GitHub Desktop.
AWS Lambda POST 요청, Javascript, https is pre-built library (no image needs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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