UNPKG

@common-creation/aws-cdk-ses-domain-identity

Version:

Constructs for provisioning and referencing domain identities which can be used in SES RuleSets and Actions Construct.

66 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomResourceHandler = void 0; const https = require("https"); class CustomResourceHandler { constructor(event) { this.event = event; } async handleEvent() { var _a; try { const { physicalResourceId, data } = await this.consumeEvent(); console.log(`Notifying success response...`); // tslint:disable-line const response = { Status: "SUCCESS", PhysicalResourceId: physicalResourceId, StackId: this.event.StackId, RequestId: this.event.RequestId, LogicalResourceId: this.event.LogicalResourceId, Data: data, }; await this.notify(response); return response; } catch (e) { console.error("Failed to provision resource!", e.stack); // tslint:disable-line const response = { Status: "FAILED", Reason: e.message, PhysicalResourceId: (_a = this.event.PhysicalResourceId) !== null && _a !== void 0 ? _a : "Unknown", StackId: this.event.StackId, RequestId: this.event.RequestId, LogicalResourceId: this.event.LogicalResourceId, Data: {}, }; await this.notify(response); return response; } } notify(response) { return new Promise((resolve, reject) => { const bufBody = Buffer.from(JSON.stringify(response), "utf8"); const req = https.request(this.event.ResponseURL, { method: "PUT", headers: { "Content-Type": "application/json", "Content-Length": bufBody.length, }, }); function onError(e) { req.removeListener("response", onResponse); reject(e); } function onResponse() { req.removeListener("error", onError) .destroy(); resolve(); } req.once("error", onError) .once("response", onResponse) .end(bufBody); }); } } exports.CustomResourceHandler = CustomResourceHandler; //# sourceMappingURL=base.js.map