我正在尝试编写AWS Lambda函数来处理dockerhub webhook响应。
我已经从AWS Lambda Cloudformation示例中修改了代码,并且在将POST请求发送回webhook respons_url之后我能够获得响应200,但webhook进程实际上并没有完成。
我在这里遗漏了什么? 有人可以对此有所了解吗?
这是功能
exports.handler = function(event, context) {
console.log("REQUEST RECEIVED:\n", JSON.stringify(event));
sendResponse(event, context, "SUCCESS");
};
function sendResponse(event, context, responseStatus, responseData) {
var responseBody = JSON.stringify({
state: responseStatus,
description: "Build ECS Description",
context: "Build ECS Context",
target_url: event.callback_url
});
console.log("RESPONSE BODY:\n", responseBody);
var https = require("https");
var url = require("url");
var parsedUrl = url.parse(event.callback_url);
var options = {
hostname: parsedUrl.hostname,
port: 443,
path: parsedUrl.path,
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "Application/json"
}
};
var request = https.request(options, function(response) {
console.log("STATUS: " + response.statusCode);
console.log("HEADERS: " + JSON.stringify(response.headers));
// Tell AWS Lambda that the function execution is done
context.done();
});
request.on("error", function(error) {
console.log("sendResponse Error:\n", error);
// Tell AWS Lambda that the function execution is done
context.done();
});
// write data to request body
request.write(responseBody);
request.end();
}