클라우드 형성에서 람다를 호출해야합니다.
다음은 내 yaml 템플릿입니다.
#test-custom-func
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
project:
Description: project
Type: String
ConstraintDescription: Any string
EnvironmentApp:
Description: EnvironmentApp
Type: String
ConstraintDescription: Any string
Description: ddddd
Resources:
removeBucket:
Type: Custom::Myfunction
Properties:
ServiceToken: arn:aws:lambda:us-east-1:xxxxxxxxx:function:test1
다음은 테스트 람다 함수입니다.
exports.handler = (event, context, callback) => {
// TODO implement
console.log("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
callback(null, 'Hello from Lambda');
};
보시다시피 모든 것이 매우 기본입니다. yaml 스택을 실행하면 생성되지 않고 생성 진행 중 상태로 유지되며 오래 후 실패합니다.
사용자 지정 기능을 사용할 때 누락 된 것이 있습니까?
callback
메서드를 사용하는 대신 CloudFormation에 명시 적으로 응답을 보내야합니다 .
문서에서 찾은이 스 니펫을 코드에 삽입 합니다.
// Send response to the pre-signed S3 URL
function sendResponse(event, context, responseStatus, responseData) {
var responseBody = JSON.stringify({
Status: responseStatus,
Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName,
PhysicalResourceId: context.logStreamName,
StackId: event.StackId,
RequestId: event.RequestId,
LogicalResourceId: event.LogicalResourceId,
Data: responseData
});
console.log("RESPONSE BODY:\n", responseBody);
var https = require("https");
var url = require("url");
var parsedUrl = url.parse(event.ResponseURL);
var options = {
hostname: parsedUrl.hostname,
port: 443,
path: parsedUrl.path,
method: "PUT",
headers: {
"content-type": "",
"content-length": responseBody.length
}
};
console.log("SENDING RESPONSE...\n");
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:" + error);
// Tell AWS Lambda that the function execution is done
context.done();
});
// write data to request body
request.write(responseBody);
request.end();
}
sendResponse
논리가 완료되면 다음과 같이 호출하십시오 .
var responseStatus = "SUCCESS";
var responseData = {};
sendResponse(event, context, responseStatus, responseData);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다