@cn-shell/aws-utils
Version:
A Cloud Native extension for AWS
100 lines (99 loc) • 2.71 kB
JavaScript
;
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, {
enumerable: true,
get: function() {
return m[k];
},
});
}
: function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});
var __setModuleDefault =
(this && this.__setModuleDefault) ||
(Object.create
? function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}
: function(o, v) {
o["default"] = v;
});
var __importStar =
(this && this.__importStar) ||
function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault =
(this && this.__importDefault) ||
function(mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FirehoseStream = void 0;
// imports here
const Aws = __importStar(require("./aws-base"));
const firehose_1 = __importDefault(require("aws-sdk/clients/firehose"));
// import AWS from "aws-sdk/global";
// AWS.config.logger = console;
// SQS consts here
const FIREHOSE_API_VER = "2015-08-04";
// Class FirehoseStream here
class FirehoseStream extends Aws.Base {
// Constructor here
constructor(name, opts) {
super(name, opts);
this._deliveryStream = opts.deliveryStream;
this._appendNewline = opts.appendNewline;
this.info("Delivery Stream Name: %s", this._deliveryStream);
// Create AWS service objects
this._fh = new firehose_1.default({
region: this._region,
apiVersion: FIREHOSE_API_VER,
});
}
// Public and Private methods here
async start() {
return true;
}
async stop() {}
async healthCheck() {
return true;
}
async injectMessage(msg) {
return await this.putRecord(msg);
}
async putRecord(msg) {
let putParams = {
DeliveryStreamName: this._deliveryStream,
Record: {
Data: `${msg}${this._appendNewline ? "\n" : ""}`,
},
};
let success = true;
await this._fh
.putRecord(putParams)
.promise()
.catch(e => {
this.error("FH putRecord Error: %s", e);
success = false;
});
if (this._playbackFile !== "") {
this.writePlayback(msg, Aws.Base.RecordTypes.FHS);
}
return success;
}
}
exports.FirehoseStream = FirehoseStream;