Created
April 24, 2026 20:29
-
-
Save smerrill/9c9ebddbb53f5766bf6b269c1ae40a16 to your computer and use it in GitHub Desktop.
AWS Node24 Lambda `cfn-response.js` content
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
| /* Copyright 2015 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. | |
| This file is licensed to you under the AWS Customer Agreement (the "License"). | |
| You may not use this file except in compliance with the License. | |
| A copy of the License is located at http://aws.amazon.com/agreement/ . | |
| This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. | |
| See the License for the specific language governing permissions and limitations under the License. */ | |
| 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: " + response.statusCode); | |
| console.log("Status message: " + response.statusMessage); | |
| resolve(); | |
| }); | |
| request.on("error", function(error) { | |
| console.log("send(..) failed executing https.request(..): " + maskCredentialsAndSignature(error)); | |
| reject(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=*****'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment