
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Leo Nodejs SDK
A Nodejs interface to interact with the Leo Platform
Documentation: https://docs.leoplatform.io
Your access key and secret key can be obtained in your AWS console. If you were not sent your keys when you signed up, contact Leo support for your access keys if you are running a managed instance.
npm install leo-sdk --save
Replace the ???? values in this example script with the appropriate values from your installation.
They can be found in Leo console. For more information on how to obtain these values, see AWS Configuration
"use strict";
//If you need to use a profile other than default
var aws = require("aws-sdk");
var awsProfile = "default";
var credentials = new aws.SharedIniFileCredentials({
profile: awsProfile
});
aws.config.credentials = credentials;
//Create the leo object with configuration to your AWS resources.
//These values are required. See docs for how to obtain them
var leo = require("leo-sdk")({
s3: "leo-s3bus-????????",
firehose: "Leo-BusToS3-????????",
kinesis: "Leo-KinesisStream-????????",
region: "us-west-2"
});
var loaderBot = "LoaderBot";
var queueName = "TestQueue";
//These are optional parameters, see the docs for possible values
var config = {};
//create a loader stream
var stream = leo.load(loaderBot, queueName, config);
for (var i = 0; i < 100; i++) {
var event = {
now: Date.now(),
index: i,
number: Math.round(Math.random() * 10000)
};
//write an event to the stream
stream.write(event);
}
// Must end the stream to finish sending the events
stream.end(err => {
err && console.log("Error:", err);
console.log("done writing events");
});
These values are not usually necessary. Only use these if you know what you are doing.
"use strict";
//If you need to use a profile other than default
var aws = require("aws-sdk");
var awsProfile = "default";
var credentials = new aws.SharedIniFileCredentials({
profile: awsProfile
});
aws.config.credentials = credentials;
//Create the leo object with configuration to your AWS resources.
//These values are required. See docs for how to obtain them
var leo = require("leo-sdk")({
s3: "leo-s3bus-????????",
firehose: "Leo-BusToS3-????????",
kinesis: "Leo-KinesisStream-????????",
region: "us-west-2"
});
var enrichmentBot = "EnrichBot";
var sourceQueue = "TestQueue";
var destinationQueue = "EnrichedQueue";
//These are optional parameters, see the docs for possible values
var config = { };
//create an enrich stream
leo.enrich({
id: enrichmentBot,
inQueue: sourceQueue,
outQueue: destinationQueue,
config: config,
transform: (payload, metadata, done) => {
//payload is the event data
//meta is info about the event, timestamps, checkpointId, etc.
//perform any kind of transformation, lookup to external dbs, or services, etc.
var event = {
time: Date.now(),
number: payload.number * -1,
newdata: "this is enriched"
};
//done function must be called in order to complete enrichment
done(null, event);
}
}, (err) => {
//this is called after all events have run through your function and been sent back to the Leo platform
console.log("finished", err || "");
});
These values are not usually necessary. Only use these if you know what you are doing.
NOTE: You should use either stopTime or runTime, not both. You may also exclude those values and the SDK will feed you events until size, loops, or limits are hit.
"use strict";
//If you need to use a profile other than default
var aws = require("aws-sdk");
var awsProfile = "default";
var credentials = new aws.SharedIniFileCredentials({
profile: "default"
});
aws.config.credentials = credentials;
//Create the leo object with configuration to your AWS resources.
//These values are required. See docs for how to obtain them
var leo = require("leo-sdk")({
s3: "leo-s3bus-????????",
firehose: "Leo-BusToS3-????????",
kinesis: "Leo-KinesisStream-????????",
region: "us-west-2"
});
var offloaderBot = "OffloaderBot";
var sourceQueue = "EnrichedQueue";
//These are optional parameters, see the docs for possible values
var config = {};
//create a loader stream
leo.offload({
id: offloaderBot,
inQueue: sourceQueue,
config: config,
batch: {
//number of events to include in this batch
size: 10000,
map: (payload, meta, done) => {
//transform events to be included in this batch
console.log("Batch Map", payload)
done(null, payload);
}
},
each: (payload, meta, done) => {
console.log("Each", meta.eid, meta.units);
//payload is object if batch isn't specified, otherwise it will be array of objects
//Do something with this payload like load to Elastic Search
//must call done to cause a checkpoint
done(null, true);
}
}, (err) => {
//this is called after all events have run through your function
console.log("All Done processing events", err || "");
});
This function will be passed events from off of the stream. They will come in the format of an object for each event, or as an array of objects if there is a batch function used to combine events.
Sometimes when loading to an external system, you do not want to send events over one at a time. For example, loading to Redshift or Elastic Search which load way more efficiently with larger batches. For this purpose, you can map events through a batching function to compile into a format that makes sense for bulk loading.
NOTE: You should use either stopTime or runTime, not both. You may also exclude those values and the SDK will feed you events until size, loops, or limits are hit.
FAQs
Load data onto the LEO Platform
The npm package leo-sdk receives a total of 655 weekly downloads. As such, leo-sdk popularity was classified as not popular.
We found that leo-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.