Last active
June 28, 2020 13:02
-
-
Save ottokruse/f08099eea65412f7376525d5d1cd968b to your computer and use it in GitHub Desktop.
A better cfn-response for NodeJS, only depends on stdlib
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
import { request } from "https"; | |
export enum Status { | |
"SUCCESS" = "SUCCESS", | |
"FAILED" = "FAILED", | |
} | |
export async function sendCfnResponse(props: { | |
event: { | |
StackId: string; | |
RequestId: string; | |
LogicalResourceId: string; | |
ResponseURL: string; | |
}; | |
status: Status; | |
reason?: string; | |
data?: { | |
[key: string]: string; | |
}; | |
physicalResourceId?: string; | |
}) { | |
const response = { | |
Status: props.status, | |
Reason: props.reason || "See CloudWatch logs", | |
PhysicalResourceId: props.physicalResourceId || "no-explicit-id", | |
StackId: props.event.StackId, | |
RequestId: props.event.RequestId, | |
LogicalResourceId: props.event.LogicalResourceId, | |
Data: props.data || {}, | |
}; | |
await new Promise((resolve, reject) => { | |
const options = { | |
method: "PUT", | |
headers: { "content-type": "" }, | |
}; | |
request(props.event.ResponseURL, options) | |
.on("error", (err) => { | |
reject(err); | |
}) | |
.end(JSON.stringify(response), "utf8", resolve); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment