Last active
March 1, 2025 15:18
-
-
Save Rud5G/bcb64bb8672a8af258274b4615f83d74 to your computer and use it in GitHub Desktop.
This file contains 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
// SPDX-License-Identifier: MIT-0 | |
exports.SUCCESS = "SUCCESS"; | |
exports.FAILED = "FAILED"; | |
exports.send = function(event, context, responseStatus, responseData, physicalResourceId, noEcho) { | |
return new Promise((resolve, reject) => { | |
var responseBody = JSON.stringify({ | |
Status: responseStatus, | |
Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName, | |
PhysicalResourceId: physicalResourceId || context.logStreamName, | |
StackId: event.StackId, | |
RequestId: event.RequestId, | |
LogicalResourceId: event.LogicalResourceId, | |
NoEcho: noEcho || false, | |
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 | |
} | |
}; | |
var request = https.request(options, function(response) { | |
console.log("Status code: " + parseInt(response.statusCode)); | |
resolve(context.done()); | |
}); | |
request.on("error", function(error) { | |
console.log("send(..) failed executing https.request(..): " + maskCredentialsAndSignature(error)); | |
reject(context.done(error)); | |
}); | |
request.write(responseBody); | |
request.end(); | |
}) | |
} | |
function maskCredentialsAndSignature(message) { | |
return message.replace(/X-Amz-Credential=[^&\s]+/i, 'X-Amz-Credential=*****') | |
.replace(/X-Amz-Signature=[^&\s]+/i, 'X-Amz-Signature=*****'); | |
} |
This file contains 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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
// SPDX-License-Identifier: MIT-0 | |
exports.SUCCESS = "SUCCESS"; | |
exports.FAILED = "FAILED"; | |
exports.send = function(event, context, responseStatus, responseData, physicalResourceId, noEcho) { | |
var responseBody = JSON.stringify({ | |
Status: responseStatus, | |
Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName, | |
PhysicalResourceId: physicalResourceId || context.logStreamName, | |
StackId: event.StackId, | |
RequestId: event.RequestId, | |
LogicalResourceId: event.LogicalResourceId, | |
NoEcho: noEcho || false, | |
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 | |
} | |
}; | |
var request = https.request(options, function(response) { | |
console.log("Status code: " + parseInt(response.statusCode)); | |
context.done(); | |
}); | |
request.on("error", function(error) { | |
console.log("send(..) failed executing https.request(..): " + maskCredentialsAndSignature(error)); | |
context.done(); | |
}); | |
request.write(responseBody); | |
request.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment