node.js – How to insert key value pairs into AWS Elasticache (Redis) using aws-sdk NodeJS
I am trying to insert key value pairs into Elasticache Redis using an npm package @aws-sdk/client-elasticache
.
The purpose of this implementation is to store a token with an ID.
This is supposed to be a lambda function so I added a layer to use this SDK and the code implementation is this:
const { ElastiCacheClient } = require("@aws-sdk/client-elasticache");
const redisOptions = {
host: "host address",
port: PORT,
};
exports.handler = async (event) => {
const client = new ElastiCacheClient(redisOptions);
const params = { "tokenKey": "SomeTokenValue" };
try {
const data = await client.middlewareStack.add(params);
console.log("DATA: ", data); // this is undefined now
} catch (err) {
throw err;
}
};
When I console.log the client
instance, I see this:
ElastiCacheClient {
middlewareStack: {
add: [Function: add],
addRelativeTo: [Function: addRelativeTo],
clone: [Function: clone],
use: [Function: use],
remove: [Function: remove],
removeByTag: [Function: removeByTag],
concat: [Function: concat],
applyToStack: [Function: cloneTo],
resolve: [Function: resolve]
},
I am not able to insert KVP into redis, what am I doing wrong here?
P.S.
client.send(params)
throws error saying send
is not a function.
Read more here: Source link