@63klabs/cache-data 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/SECURITY.md +1 -1
- package/package.json +1 -1
- package/src/lib/tools/vars.js +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
A package for node.js applications to access and cache data from remote API endpoints or other sources using AWS S3 and DynamoDb.
|
|
4
4
|
|
|
5
|
-
> Note: This repository and package
|
|
5
|
+
> Note: This repository and package has moved from chadkluck to 63Klabs but is still managed by the same developer.
|
|
6
6
|
|
|
7
|
-
[@
|
|
7
|
+
[@63klabs/cache-data on npmjs.com](https://www.npmjs.com/package/@63klabs/cache-data)
|
|
8
8
|
|
|
9
9
|
## Description
|
|
10
10
|
|
|
@@ -29,7 +29,7 @@ This package has been used in production for applications receiving over 1 milli
|
|
|
29
29
|
1. Make sure your function is using an AWS Lambda supported version of Node and has at least 256MB allocated (512-1024MB recommended).
|
|
30
30
|
2. Add the cache-data environment variables to your Lambda function. Also update your Lambda's execution role to access your S3 and DynamoDb.
|
|
31
31
|
3. Add an S3 bucket and DynamoDb table to store your cache either in the application CloudFormation template or as separate infrastructure.
|
|
32
|
-
4. Install the @
|
|
32
|
+
4. Install the @63klabs/cache-data package `npm install @63klabs/cache-data`
|
|
33
33
|
5. Add the cache code to your Lambda function
|
|
34
34
|
|
|
35
35
|
#### Lambda Memory Allocation
|
|
@@ -85,7 +85,7 @@ Resources:
|
|
|
85
85
|
deployEnvironment: "TEST" # "PROD"
|
|
86
86
|
paramStore: "/" # SSM Parameter store can use a hierarchy to organize your apps parameters
|
|
87
87
|
|
|
88
|
-
# Cache-Data settings (from: https://www.npmjs.com/package/@
|
|
88
|
+
# Cache-Data settings (from: https://www.npmjs.com/package/@63klabs/cache-data)
|
|
89
89
|
CacheData_DynamoDbTable: !Ref CacheDataDynamoDbTable
|
|
90
90
|
CacheData_S3Bucket: !Ref CacheDataS3Bucket
|
|
91
91
|
CacheData_CryptSecureDataAlgorithm: !Ref CacheDataCryptSecureDataAlg
|
|
@@ -134,7 +134,7 @@ Resources:
|
|
|
134
134
|
Effect: Allow
|
|
135
135
|
Resource: !GetAtt AppLogGroup.Arn
|
|
136
136
|
|
|
137
|
-
# cache-data Parameter Read Access (from: https://www.npmjs.com/package/@
|
|
137
|
+
# cache-data Parameter Read Access (from: https://www.npmjs.com/package/@63klabs/cache-data)
|
|
138
138
|
- Sid: LambdaAccessToSSMParameters
|
|
139
139
|
Action:
|
|
140
140
|
- ssm:DescribeParameters
|
|
@@ -145,7 +145,7 @@ Resources:
|
|
|
145
145
|
Resource:
|
|
146
146
|
- !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter${ParameterStoreHierarchy}*"
|
|
147
147
|
|
|
148
|
-
# cache-data S3 bucket (from: https://www.npmjs.com/package/@
|
|
148
|
+
# cache-data S3 bucket (from: https://www.npmjs.com/package/@63klabs/cache-data)
|
|
149
149
|
- Sid: LambdaAccessToS3BucketCacheData
|
|
150
150
|
Action:
|
|
151
151
|
- s3:PutObject
|
|
@@ -154,7 +154,7 @@ Resources:
|
|
|
154
154
|
Effect: Allow
|
|
155
155
|
Resource: !Join [ '', [ !GetAtt CacheDataS3Bucket.Arn, '/cache/*' ] ]
|
|
156
156
|
|
|
157
|
-
# cache-data DynamoDb table (from: https://www.npmjs.com/package/@
|
|
157
|
+
# cache-data DynamoDb table (from: https://www.npmjs.com/package/@63klabs/cache-data)
|
|
158
158
|
- Sid: LambdaAccessToDynamoDBTableCacheData
|
|
159
159
|
Action:
|
|
160
160
|
- dynamodb:GetItem
|
|
@@ -177,7 +177,7 @@ Parameters:
|
|
|
177
177
|
|
|
178
178
|
# ---------------------------------------------------------------------------
|
|
179
179
|
# Cache-Data Parameters
|
|
180
|
-
# From: https://www.npmjs.com/package/@
|
|
180
|
+
# From: https://www.npmjs.com/package/@63klabs/cache-data
|
|
181
181
|
|
|
182
182
|
CacheDataDbMaxCacheSizeInKB:
|
|
183
183
|
Type: Number
|
|
@@ -244,7 +244,7 @@ Resources:
|
|
|
244
244
|
|
|
245
245
|
# ---------------------------------------------------------------------------
|
|
246
246
|
# Cache-Data
|
|
247
|
-
# From: https://www.npmjs.com/package/@
|
|
247
|
+
# From: https://www.npmjs.com/package/@63klabs/cache-data
|
|
248
248
|
# Your Lambda function will need access via the Execution Role
|
|
249
249
|
|
|
250
250
|
# -- Cache-Data DynamoDb Table --
|
|
@@ -318,14 +318,14 @@ Resources:
|
|
|
318
318
|
#### Install npm Package and Add Starter Code
|
|
319
319
|
|
|
320
320
|
1. Go to your application directory
|
|
321
|
-
2. Run the command `npm i @
|
|
322
|
-
3. Add `const { tools, cache, endpoint } = require('@
|
|
321
|
+
2. Run the command `npm i @63klabs/cache-data`
|
|
322
|
+
3. Add `const { tools, cache, endpoint } = require('@63klabs/cache-data');` to your script
|
|
323
323
|
4. Add a Config class to your script. This should be placed before the handler so it only is defined during cold starts. This can also be imported from a separate script.
|
|
324
324
|
5. Add `Config.init()` after the Config class but before the handler.
|
|
325
325
|
5. Add `await tools.Config.promise();` in the handler to make sure the Config has completed.
|
|
326
326
|
|
|
327
327
|
```javascript
|
|
328
|
-
const { tools, cache, endpoint } = require('@
|
|
328
|
+
const { tools, cache, endpoint } = require('@63klabs/cache-data');
|
|
329
329
|
|
|
330
330
|
class Config extends tools._ConfigSuperClass {
|
|
331
331
|
static async init() {
|
|
@@ -487,7 +487,7 @@ This code can be put into a separate file and brought in using a `require` state
|
|
|
487
487
|
/* EXAMPLE USING the this._initParameters method of obtaining parameters during Config.init() */
|
|
488
488
|
|
|
489
489
|
// require cache-data
|
|
490
|
-
const { tools, cache, endpoint } = require('@
|
|
490
|
+
const { tools, cache, endpoint } = require('@63klabs/cache-data');
|
|
491
491
|
|
|
492
492
|
/**
|
|
493
493
|
* Extends tools._ConfigSuperClass
|
|
@@ -634,7 +634,7 @@ Once the `Config` object is initialized, the following code can be used to acces
|
|
|
634
634
|
/*
|
|
635
635
|
Note that cache object was already set by the require statement
|
|
636
636
|
assuming:
|
|
637
|
-
const { tools, cache, endpoint } = require('@
|
|
637
|
+
const { tools, cache, endpoint } = require('@63klabs/cache-data');
|
|
638
638
|
*/
|
|
639
639
|
|
|
640
640
|
let connection = Config.getConnection("demo"); // corresponds with the name we gave it during connections.add()
|
|
@@ -886,7 +886,7 @@ In its simplist form we can do the following:
|
|
|
886
886
|
```js
|
|
887
887
|
/*
|
|
888
888
|
Assuming:
|
|
889
|
-
const { tools, cache, endpoint } = require('@
|
|
889
|
+
const { tools, cache, endpoint } = require('@63klabs/cache-data');
|
|
890
890
|
*/
|
|
891
891
|
|
|
892
892
|
const timerTaskGetGames = new tools.Timer("Getting games", true); // We give it a name for logging, and we set to true so the timer starts right away
|
|
@@ -911,7 +911,7 @@ You are able to get the current time elapsed in milliseconds from a running Time
|
|
|
911
911
|
```js
|
|
912
912
|
/*
|
|
913
913
|
Assuming:
|
|
914
|
-
const { tools, cache, endpoint } = require('@
|
|
914
|
+
const { tools, cache, endpoint } = require('@63klabs/cache-data');
|
|
915
915
|
*/
|
|
916
916
|
|
|
917
917
|
/* increase the log level - comment out when not needed */
|
|
@@ -1044,13 +1044,13 @@ console.log( tools.obfuscate(str, opt) );
|
|
|
1044
1044
|
|
|
1045
1045
|
### AWS-SDK
|
|
1046
1046
|
|
|
1047
|
-
The @
|
|
1047
|
+
The @63klabs/cache-data package will automatically detect and use the correct AWS SDK based on the version of Node.
|
|
1048
1048
|
|
|
1049
1049
|
Node 16 environments will use AWS-SDK version 2.
|
|
1050
1050
|
|
|
1051
1051
|
Node 18+ environments will use AWS-SDK version 3.
|
|
1052
1052
|
|
|
1053
|
-
Note that `package.json` for @
|
|
1053
|
+
Note that `package.json` for @63klabs/cache-data only installs the AWS-SDK on dev environments. This is because AWS Lambda already includes the AWS-SDK without requiring installs. This makes your application lighter and ensures you are always running the most recent SDK release. Given this, that means that AWS SDK v3 is not available in Lambda functions using Node 16, and v2 is not available in Lambda Node >=18 environments.
|
|
1054
1054
|
|
|
1055
1055
|
Because DynamoDb, S3, and SSM Parameter store are used by cache-data, only those SDKs are included. A client is provided for each along with limited number of commands. To make gets and puts easier a get and put command is mapped for DynamoDb and S3. (Uses appropriate commands underneath for V2 and V3 so your code wouldn't need to change.)
|
|
1056
1056
|
|
|
@@ -1059,7 +1059,7 @@ Because DynamoDb, S3, and SSM Parameter store are used by cache-data, only those
|
|
|
1059
1059
|
When `tools` is imported, you can use the `tools.AWS` object to perform common read/write operations on S3, DynamoDb, and SSM Parameter Store.
|
|
1060
1060
|
|
|
1061
1061
|
```javascript
|
|
1062
|
-
const { tools } = require('@
|
|
1062
|
+
const { tools } = require('@63klabs/cache-data');
|
|
1063
1063
|
|
|
1064
1064
|
console.log(`NODE VERSION ${tools.AWS.NODE_VER} USING AWS SDK ${tools.AWS.SDK_VER}`);
|
|
1065
1065
|
console.log(`REGION: ${tools.AWS.REGION}`); // set from Lambda environment variable AWS_REGION
|
|
@@ -1184,7 +1184,7 @@ const dbGetResult = await dbDocClient.send(GetCommand(paramsForGetRecord));
|
|
|
1184
1184
|
|
|
1185
1185
|
```javascript
|
|
1186
1186
|
// Using tools to handle the SDK version and basic calls for you
|
|
1187
|
-
const { tools } = require('@
|
|
1187
|
+
const { tools } = require('@63klabs/cache-data');
|
|
1188
1188
|
|
|
1189
1189
|
const dbPutResult = await tools.AWS.dynamodb.put(paramsForNewRecord);
|
|
1190
1190
|
const dbGetResult = await tools.AWS.dynamodb.get(paramsForGetRecrod);
|
|
@@ -1203,7 +1203,7 @@ For more on creating parameter/query objects for S3, DynamoDb, and SSM Parameter
|
|
|
1203
1203
|
When using AWS SDK version 3, you can import additional commands and use them with the client provided by `tools.AWS`.
|
|
1204
1204
|
|
|
1205
1205
|
```javascript
|
|
1206
|
-
const { tools } = require('@
|
|
1206
|
+
const { tools } = require('@63klabs/cache-data');
|
|
1207
1207
|
const { DeleteObjectCommand } = require('@aws-sdk/client-s3'); // AWS SDK v3
|
|
1208
1208
|
|
|
1209
1209
|
const command = new DeleteObjectCommand({
|
|
@@ -1220,7 +1220,7 @@ Because Node 16 and the AWS SDK v2 is being deprecated, this documentation will
|
|
|
1220
1220
|
|
|
1221
1221
|
```js
|
|
1222
1222
|
// NodeJS 16 using AWS SDK v2
|
|
1223
|
-
const {tools} = require("@
|
|
1223
|
+
const {tools} = require("@63klabs/cache-data");
|
|
1224
1224
|
|
|
1225
1225
|
// using the provided S3 client
|
|
1226
1226
|
const s3result1 = await tools.AWS.s3.client.putObject(params).promise();
|
|
@@ -1253,7 +1253,7 @@ Make sure you have your S3 bucket, DynamoDb table, and SSM Parameter store set u
|
|
|
1253
1253
|
|
|
1254
1254
|
- [Website](https://chadkluck.me/)
|
|
1255
1255
|
- [GitHub](https://github.com/chadkluck)
|
|
1256
|
-
- [Mastodon: @
|
|
1256
|
+
- [Mastodon: @63klabs@universeodon.com](https://universeodon.com/@63klabs)
|
|
1257
1257
|
- [X: @ChadKluck](https://x.com/chadkluck)
|
|
1258
1258
|
|
|
1259
1259
|
## Version History
|
package/SECURITY.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
## Reporting a Vulnerability
|
|
4
4
|
|
|
5
|
-
Report all vulnerabilities under the [Security menu in the Cache-Data GitHub repository](https://github.com/
|
|
5
|
+
Report all vulnerabilities under the [Security menu in the Cache-Data GitHub repository](https://github.com/63klabs/npm-cache-data/security/advisories).
|
package/package.json
CHANGED
package/src/lib/tools/vars.js
CHANGED
|
@@ -22,7 +22,7 @@ const nodeVerMinor = AWS.NODE_VER_MINOR;
|
|
|
22
22
|
const nodeVerMajorMinor = AWS.NODE_VER_MAJOR_MINOR;
|
|
23
23
|
|
|
24
24
|
if (nodeVerMajor < 16) {
|
|
25
|
-
console.error(`Node.js version 16 or higher is required for @
|
|
25
|
+
console.error(`Node.js version 16 or higher is required for @63klabs/cache-data. Version ${nodeVer} detected. Please install at least Node version 16 (>18 preferred) in your environment.`);
|
|
26
26
|
process.exit(1);
|
|
27
27
|
}
|
|
28
28
|
|