aws-core-utils
Advanced tools
Comparing version 5.0.4 to 5.0.5
{ | ||
"name": "aws-core-utils", | ||
"version": "5.0.4", | ||
"version": "5.0.5", | ||
"description": "Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc.", | ||
@@ -14,4 +14,4 @@ "author": "Byron du Preez", | ||
"dependencies": { | ||
"core-functions": "^2.0.9", | ||
"logging-utils": "^3.0.3", | ||
"core-functions": "^2.0.10", | ||
"logging-utils": "^3.0.5", | ||
"deep-equal": "^1.0.1" | ||
@@ -18,0 +18,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# aws-core-utils v5.0.4 | ||
# aws-core-utils v5.0.5 | ||
@@ -294,2 +294,13 @@ Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc. | ||
### 5.0.5 | ||
- Changes to `stream-events` module: | ||
- Added new `getEventSources` function | ||
- Added new `getDynamoDBEventSourceTableNames` function | ||
- Changes to `stages` module: | ||
- Changed `resolveStage` function to resolve the event's eventSource and when its DynamoDB to use the table names | ||
of the DynamoDB stream event as a stage source, instead of always assuming the event is a Kinesis stream event | ||
and only using the stream names of the Kinesis stream event as a stage source | ||
- Updated `core-functions` dependency to version 2.0.10 | ||
- Updated `logging-utils` dependency to version 3.0.5 | ||
### 5.0.4 | ||
@@ -453,5 +464,2 @@ - Updated `core-functions` dependency to version 2.0.9 | ||
### 0.9.0 | ||
- Initial commit | ||
- Initial commit |
@@ -386,10 +386,12 @@ 'use strict'; | ||
* | ||
* 6. Extracts the stream names from the AWS event's records' eventSourceARNs (if any) and then uses the given context's | ||
* configured stageHandling.extractStageFromStreamName function (if defined) to extract the stages from these stream | ||
* names and returns the first non-blank stage (if any and if there are NOT multiple distinct results). | ||
* 6. Extracts the stream (or table) names from the AWS event's records' eventSourceARNs (if any) and then uses the | ||
* given context's configured stageHandling.extractStageFromStreamName (or stageHandling.extractStageFromResourceName) | ||
* function (if defined) to extract the stages from these stream (or table) names and returns the first non-blank | ||
* stage (if any and if there are NOT multiple distinct results). | ||
* | ||
* NB: This step relies on a convention of qualifying stream names with a stage. If you are NOT using such a | ||
* convention, then disable this step by simply NOT configuring a stageHandling.extractStageFromStreamName function | ||
* on the context (see {@linkcode configureStageHandling}). Note that doing this will also disable the | ||
* {@linkcode extractStageFromQualifiedStreamName} function. | ||
* NB: This step relies on a convention of qualifying stream and table names with a stage. If you are NOT using such | ||
* a convention, then disable this step by simply NOT configuring stageHandling.extractStageFromStreamName and | ||
* stageHandling.extractStageFromResourceName functions on the context (see {@linkcode configureStageHandling}). | ||
* Note that doing this will also disable the {@linkcode extractStageFromQualifiedStreamName} and | ||
* {@linkcode extractStageFromQualifiedResourceName} functions. | ||
* | ||
@@ -420,2 +422,4 @@ * 7. Uses context.stageHandling.defaultStage (if non-blank). | ||
* context that accepts: a stage-qualified stream name; and a context, and extracts a stage from the stream name | ||
* @param {Function|undefined} [context.stageHandling.extractStageFromResourceName] - an optional function on the given | ||
* context that accepts: a stage-qualified resource (e.g. table) name; and a context, and extracts a stage from the resource name | ||
* @param {string|undefined} [context.stageHandling.defaultStage] - an optional default stage on the given context to | ||
@@ -450,3 +454,3 @@ * use as a second last resort if all other attempts fail (configure this via configureStageHandling) | ||
if (isNotBlank(stage)) { | ||
if (isNotBlank(stage) && stage !== 'undefined' && stage !== 'null') { | ||
context.debug(`Resolved stage (${stage}) from process.env.${envStageName}`); | ||
@@ -493,22 +497,51 @@ return toCase(trim(stage), extractInCase); | ||
// Attempt 6 | ||
// Check have all the pieces needed to extract a stream name and apply the given extractStageFromStreamName function to it | ||
const extractStageFromStreamName = getStageHandlingFunction(context, EXTRACT_STAGE_FROM_STREAM_NAME_SETTING); | ||
const eventSources = Arrays.distinct(streamEvents.getEventSources(event).filter(isNotBlank)); | ||
if (extractStageFromStreamName && event && event.Records) { | ||
const stages = streamEvents.getKinesisEventSourceStreamNames(event) | ||
.map(streamName => isNotBlank(streamName) ? extractStageFromStreamName(trim(streamName), context) : ''); | ||
if (eventSources.length < 1) { | ||
// No eventSources | ||
context.warn(`Cannot resolve a stage from a stream or table name from an event WITHOUT an eventSource - event (${stringify(event)})!`); | ||
} else if (eventSources.length > 1) { | ||
// Multiple distinct eventSources | ||
context.warn(`Cannot resolve a stage from a stream or table name from an event with MULTIPLE distinct event sources ${stringify(eventSources)} - event (${stringify(event)})!`); | ||
} else { | ||
// Only 1 distinct eventSource | ||
const eventSource = eventSources[0]; | ||
const eventSourceIsKinesis = eventSource === 'aws:kinesis'; | ||
const eventSourceIsDynamoDB = eventSource === 'aws:dynamodb'; | ||
let stages = []; | ||
let stage = stages.find(s => isNotBlank(s)); | ||
if (!eventSourceIsKinesis && !eventSourceIsDynamoDB) { | ||
context.warn(`Cannot resolve a stage from a stream or table name from an event with an unexpected event source ${eventSource} - event (${stringify(event)})!`); | ||
} else { | ||
if (eventSourceIsKinesis) { | ||
// Check have all the pieces needed to extract a stream name and apply the given extractStageFromStreamName function to it | ||
const extractStageFromStreamName = getStageHandlingFunction(context, EXTRACT_STAGE_FROM_STREAM_NAME_SETTING); | ||
if (extractStageFromStreamName && event && event.Records) { | ||
stages = streamEvents.getKinesisEventSourceStreamNames(event) | ||
.map(streamName => isNotBlank(streamName) ? extractStageFromStreamName(trim(streamName), context) : '') | ||
.filter(isNotBlank); | ||
} | ||
} else if (eventSourceIsDynamoDB) { | ||
// Check have all the pieces needed to extract a table name and apply the given extractStageFromResourceName function to it | ||
const extractStageFromTableName = getStageHandlingFunction(context, EXTRACT_STAGE_FROM_RESOURCE_NAME_SETTING); | ||
if (extractStageFromTableName && event && event.Records) { | ||
stages = streamEvents.getDynamoDBEventSourceTableNames(event) | ||
.map(tableName => isNotBlank(tableName) ? extractStageFromTableName(trim(tableName), context) : '') | ||
.filter(isNotBlank); | ||
} | ||
} | ||
let stage = stages.length > 0 ? stages[0] : undefined; | ||
if (stages.length > 1) { | ||
const distinctStages = Arrays.distinct(stages); | ||
if (distinctStages > 1) { | ||
context.warn(`WARNING - Ignoring arbitrary first stage (${stage}), since found MULTIPLE distinct stages ${stringify(distinctStages)} on event (${stringify(event)})!`); | ||
stage = ''; // too many choices, so choose none | ||
if (stages.length > 1) { | ||
const distinctStages = Arrays.distinct(stages); | ||
if (distinctStages > 1) { | ||
context.warn(`WARNING - Ignoring arbitrary first stage (${stage}), since found MULTIPLE distinct stages ${stringify(distinctStages)} on event (${stringify(event)})!`); | ||
stage = ''; // too many choices, so choose none | ||
} | ||
} | ||
} | ||
if (isNotBlank(stage)) { | ||
context.debug(`Resolved stage (${stage}) from event source ARN stream name`); | ||
return toCase(trim(stage), extractInCase); | ||
if (isNotBlank(stage)) { | ||
context.debug(`Resolved stage (${stage}) from event source ARN ${eventSourceIsKinesis ? 'stream' : 'table'} name`); | ||
return toCase(trim(stage), extractInCase); | ||
} | ||
} | ||
@@ -537,2 +570,3 @@ } | ||
//noinspection JSUnusedLocalSymbols | ||
/** | ||
@@ -539,0 +573,0 @@ * A default convertAliasToStage function that simply returns the given alias (if any) exactly as it is as the stage. |
@@ -16,2 +16,4 @@ 'use strict'; | ||
getEventSourceARNs: getEventSourceARNs, | ||
/** Returns the event sources of the given stream event's records */ | ||
getEventSources: getEventSources, | ||
@@ -23,2 +25,4 @@ /** Extracts and returns the stream names from the given Kinesis stream event's records' eventSourceARNs */ | ||
/** Extracts and returns the table names from the given DynamoDB stream event records' eventSourceARNs */ | ||
getDynamoDBEventSourceTableNames: getDynamoDBEventSourceTableNames, | ||
/** Extracts and returns the table name from the given DynamoDB stream event record's eventSourceARN */ | ||
@@ -50,5 +54,14 @@ getDynamoDBEventSourceTableName: getDynamoDBEventSourceTableName, | ||
/** | ||
* Returns the event sources of the given stream event's records (if any); otherwise returns an empty array. | ||
* @param event - a Kinesis or DynamoDB stream event | ||
* @returns {string[]} an array of event sources (one for each stream event record) | ||
*/ | ||
function getEventSources(event) { | ||
return event && event.Records ? event.Records.map(r => r.eventSource) : []; | ||
} | ||
/** | ||
* Extracts and returns the stream names from the given Kinesis stream event's records' eventSourceARNs (if any); otherwise | ||
* returns an empty array. | ||
* @param event - a Kinesis or DynamoDB stream event | ||
* @param event - a Kinesis stream event | ||
* @returns {string[]} an array of event source stream names (one for each stream event record) | ||
@@ -91,2 +104,12 @@ */ | ||
/** | ||
* Extracts and returns the table names from the given DynamoDB stream event's records' eventSourceARNs (if any); | ||
* otherwise returns an empty array. | ||
* @param event - a DynamoDB stream event | ||
* @returns {string[]} an array of event source table names (one for each stream event record) | ||
*/ | ||
function getDynamoDBEventSourceTableNames(event) { | ||
return event && event.Records ? event.Records.map(getDynamoDBEventSourceTableName) : []; | ||
} | ||
/** | ||
* Extracts and returns the table name from the given DynamoDB stream event record's eventSourceARN (if any); otherwise | ||
@@ -100,2 +123,3 @@ * returns an empty string. | ||
} | ||
/** | ||
@@ -102,0 +126,0 @@ * Validates the given stream event record and raises an error if the record fails to meet any of the following criteria: |
{ | ||
"name": "aws-core-utils-tests", | ||
"description": "Unit tests for aws-core-utils modules", | ||
"version": "5.0.4", | ||
"version": "5.0.5", | ||
"author": "Byron du Preez", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
305654
4382
463
Updatedcore-functions@^2.0.10
Updatedlogging-utils@^3.0.5