Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-core-utils

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-core-utils - npm Package Compare versions

Comparing version 7.0.4 to 7.0.5

4

api-lambdas.js

@@ -134,3 +134,3 @@ 'use strict';

// Log the error encountered
context.error(isNotBlank(failureMsg) ? failureMsg : 'Failed to execute Lambda', err.stack);
context.error(isNotBlank(failureMsg) ? failureMsg : 'Failed to execute Lambda', err);
failCallback(callback, err, awsContext, undefined, undefined, allowedHttpStatusCodes);

@@ -141,3 +141,3 @@ }

} catch (err) {
log(context, LogLevel.ERROR, isNotBlank(failureMsg) ? failureMsg : 'Failed to execute Lambda', err.stack);
log(context, LogLevel.ERROR, isNotBlank(failureMsg) ? failureMsg : 'Failed to execute Lambda', err);
// Fail the Lambda callback

@@ -144,0 +144,0 @@ failCallback(callback, err, awsContext, undefined, undefined, allowedHttpStatusCodes);

@@ -157,2 +157,2 @@ 'use strict';

return context;
}
}

@@ -52,3 +52,3 @@ 'use strict';

.catch(err => {
context.error(`Failed to load ${desc} from ${tableName}`, err.stack);
context.error(`Failed to load ${desc} from ${tableName}`, err);
throw err;

@@ -58,3 +58,3 @@ });

} catch (err) {
context.error(`Failed to load ${desc} from ${tableName}`, err.stack);
context.error(`Failed to load ${desc} from ${tableName}`, err);
return Promise.reject(err);

@@ -61,0 +61,0 @@ }

@@ -41,5 +41,5 @@ 'use strict';

const functionName = params.FunctionName;
const listEventSourceMappingsAsync = Promises.wrapMethod(lambda, lambda.listEventSourceMappings);
const listEventSourceMappingsAsync = Promises.wrap(lambda.listEventSourceMappings);
const startMs = Date.now();
return listEventSourceMappingsAsync(params).then(
return listEventSourceMappingsAsync.call(lambda, params).then(
result => {

@@ -71,5 +71,5 @@ if (logger.traceEnabled) {

const uuid = params.UUID;
const updateEventSourceMappingAsync = Promises.wrapMethod(lambda, lambda.updateEventSourceMapping);
const updateEventSourceMappingAsync = Promises.wrap(lambda.updateEventSourceMapping);
const startMs = Date.now();
return updateEventSourceMappingAsync(params).then(
return updateEventSourceMappingAsync.call(lambda, params).then(
result => {

@@ -97,5 +97,5 @@ logger.info(`Updated event source mapping (${uuid}) for function (${functionName}) - took ${Date.now() - startMs} ms - result (${JSON.stringify(result)})`);

const params = {FunctionName: functionName, UUID: uuid, Enabled: false};
const updateEventSourceMappingAsync = Promises.wrapMethod(lambda, lambda.updateEventSourceMapping);
const updateEventSourceMappingAsync = Promises.wrap(lambda.updateEventSourceMapping);
const startMs = Date.now();
return updateEventSourceMappingAsync(params).then(
return updateEventSourceMappingAsync.call(lambda, params).then(
result => {

@@ -102,0 +102,0 @@ logger.info(`Disabled event source mapping (${uuid}) for function (${functionName}) - took ${Date.now() - startMs} ms - result (${JSON.stringify(result)})`);

@@ -6,5 +6,2 @@ 'use strict';

const Strings = require('core-functions/strings');
const isNotBlank = Strings.isNotBlank;
const appErrors = require('core-functions/app-errors');

@@ -31,2 +28,3 @@

exports.getInvokedFunctionArnFunctionName = getInvokedFunctionArnFunctionName;
exports.getInvokedFunctionNameWithAliasOrVersion = getInvokedFunctionNameWithAliasOrVersion;

@@ -75,2 +73,16 @@ // Function to assist with failing the callback of an AWS Lambda (not exposed via API Gateway) and preserve the information of the error thrown

/**
* Extracts and returns a concatenation of the invoked function name and the invoked alias or version (if any) separated
* by a colon from the given AWS Lambda context's invokedFunctionArn.
* @param {AWSContext} awsContext - the AWS context
* @returns {string} the invoked function name with the invoked alias or version (if any); otherwise an empty string
*/
function getInvokedFunctionNameWithAliasOrVersion(awsContext) {
const invokedFunctionArn = awsContext && awsContext.invokedFunctionArn;
const resources = getArnResources(invokedFunctionArn);
const functionName = resources.resource;
const aliasOrVersion = resources.aliasOrVersion;
return functionName ? aliasOrVersion ? `${functionName}:${aliasOrVersion}` : functionName : '';
}
/**
* Returns the function name, version and alias (if any) from the given AWS context, which was passed to your Lambda

@@ -97,3 +109,4 @@ * function.

const nameFromArn = resources.resource;
if (nameFromArn !== nameFromContext) {
if (nameFromContext && nameFromArn && nameFromArn !== nameFromContext) {
console.warn(`Lambda context with function name (${nameFromContext}) has different name (${nameFromArn}) in invoked function ARN`);

@@ -103,6 +116,14 @@ }

const aliasOrVersion = resources.aliasOrVersion;
const alias = isNotBlank(aliasOrVersion) && aliasOrVersion !== versionFromContext ? //&& aliasOrVersion !== version ?
const alias = aliasOrVersion && aliasOrVersion !== versionFromContext ? //&& aliasOrVersion !== version ?
aliasOrVersion : '';
return {functionName: name || nameFromContext || '', version: version || versionFromContext || '', alias: alias};
const invokedFunctionNameWithAliasOrVersion = nameFromArn ? aliasOrVersion ?
`${nameFromArn}:${aliasOrVersion}` : nameFromArn : '';
return {
functionName: name || nameFromContext || '',
version: version || versionFromContext || '',
alias: alias,
invoked: invokedFunctionNameWithAliasOrVersion
};
}

@@ -122,3 +143,10 @@

function getAlias(awsContext) {
return getFunctionNameVersionAndAlias(awsContext).alias;
const invokedFunctionArn = awsContext && awsContext.invokedFunctionArn;
const resources = getArnResources(invokedFunctionArn);
const versionFromContext = awsContext && awsContext.functionVersion;
const aliasOrVersion = resources.aliasOrVersion;
return aliasOrVersion && aliasOrVersion !== versionFromContext ? //&& aliasOrVersion !== version ?
aliasOrVersion : '';
}

@@ -148,3 +176,2 @@

lambdaCallback(JSON.stringify(appError));
}
}
{
"name": "aws-core-utils",
"version": "7.0.4",
"version": "7.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": "3.0.14",
"logging-utils": "4.0.13",
"core-functions": "3.0.15",
"logging-utils": "4.0.14",
"deep-equal": "1.0.1"

@@ -18,0 +18,0 @@ },

@@ -1,2 +0,2 @@

# aws-core-utils v7.0.4
# aws-core-utils v7.0.5

@@ -96,3 +96,3 @@ Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc.

} else {
context.error('Failed to ...', err.stack);
context.error('Failed to ...', err);
}

@@ -105,3 +105,3 @@ apiLambdas.failCallback(callback, err, awsContext);

// i.e. [400, 401, 403, 404, 408, 429, 500, 502, 503, 504]
context.error('Failed to ...', err.stack);
context.error('Failed to ...', err);
apiLambdas.failCallback(callback, err, awsContext);

@@ -108,0 +108,0 @@ }

## Changes
### 7.0.5
- Changes to `lambdas` module:
- Added new `getInvokedFunctionNameWithAliasOrVersion` function
- Changed the `getFunctionNameVersionAndAlias` function to also return an `invoked` property containing the same
concatenation of invoked function name & alias or version generated by `getInvokedFunctionNameWithAliasOrVersion`
- Changes to `type-defs` module:
- Added new `invoked` property to `LambdaFunctionNameVersionAndAlias` type definition
- Changes to `lambda-utils` module:
- Replaced uses of deprecated `Promises.wrapMethod` with `Promises.wrap`
- Replaced all logging of `error.stack` with logging of just the error
- Updated `core-functions` dependency to version 3.0.15
- Updated `logging-utils` dependency to version 4.0.14
### 7.0.4

@@ -4,0 +17,0 @@ - Changed almost all modules' exports to modifications of the default `exports` object instead of replacing the default `module.exports` object

@@ -97,3 +97,3 @@ 'use strict';

.catch(err => {
t.fail(`handler should not have failed - ${err.stack}`);
t.fail(`handler should not have failed - ${err}`);
t.end();

@@ -103,3 +103,3 @@ });

} catch (err) {
t.fail(`handler should not have failed in try-catch - ${err.stack}`);
t.fail(`handler should not have failed in try-catch - ${err}`);
t.end();

@@ -161,3 +161,3 @@

} catch (err) {
t.fail(`handler should not have failed in try-catch - ${err.stack}`);
t.fail(`handler should not have failed in try-catch - ${err}`);
t.end();

@@ -220,3 +220,3 @@

} catch (err) {
t.fail(`handler should not have failed in try-catch - ${err.stack}`);
t.fail(`handler should not have failed in try-catch - ${err}`);
t.end();

@@ -267,3 +267,3 @@

.catch(err => {
t.fail(`handler should not have failed - ${err.stack}`);
t.fail(`handler should not have failed - ${err}`);
t.end();

@@ -273,3 +273,3 @@ });

} catch (err) {
t.fail(`handler should not have failed in try-catch - ${err.stack}`);
t.fail(`handler should not have failed in try-catch - ${err}`);
t.end();

@@ -276,0 +276,0 @@

@@ -65,3 +65,3 @@ 'use strict';

const region = process.env.AWS_REGION;
const functionName = 'sampleFunctionName';
const functionName = 'sample-function-name';
const invokedFunctionArn = samples.sampleInvokedFunctionArn(region, functionName, functionAlias);

@@ -389,4 +389,7 @@ return samples.sampleAwsContext(functionName, functionVersion, invokedFunctionArn);

const awsContext = sampleAwsContext('1.0.1', 'dev1');
const invokedLambda = {functionName: 'sampleFunctionName', version: '1.0.1', alias: 'dev1'};
const functionName = 'sample-function-name';
const invoked = `${functionName}:dev1`;
const invokedLambda = {functionName: functionName, version: '1.0.1', alias: 'dev1', invoked: invoked};
contexts.configureStandardContext(context, standardSettings, standardOptions, event, awsContext, false);

@@ -419,4 +422,7 @@

t.equal(context.awsContext, awsContext, 'context.awsContext must be awsContext');
t.ok(context.invokedLambda, 'context.invokedLambda must be defined');
t.deepEqual(context.invokedLambda, invokedLambda, `context.invokedLambda must be ${JSON.stringify(invokedLambda)}`);
t.ok(context.invokedLambda.invoked, 'context.invokedLambda.invoked must be defined');
t.equal(context.invokedLambda.invoked, invoked, `context.invokedLambda.invoked must be ${JSON.stringify(invoked)}`);

@@ -457,3 +463,4 @@ t.ok(context.stage, 'context.stage must be defined');

const invokedLambda = {functionName: functionName, version: functionVersion, alias: functionAlias};
const invoked = 'sample-function-name:dev1';
const invokedLambda = {functionName: functionName, version: functionVersion, alias: 'dev1', invoked: invoked};

@@ -475,4 +482,7 @@ // Initial configuration WITHOUT event & AWS context

t.equal(context.awsContext, awsContext, 'context.awsContext must be awsContext');
t.ok(context.invokedLambda, 'context.invokedLambda must be defined');
t.deepEqual(context.invokedLambda, invokedLambda, `context.invokedLambda must be ${JSON.stringify(invokedLambda)}`);
t.ok(context.invokedLambda.invoked, 'context.invokedLambda.invoked must be defined');
t.equal(context.invokedLambda.invoked, invoked, `context.invokedLambda.invoked must be ${JSON.stringify(invoked)}`);

@@ -479,0 +489,0 @@ t.equal(context.stage, expectedStage, `context.stage must be ${expectedStage}`);

@@ -18,2 +18,3 @@ 'use strict';

const getInvokedFunctionArnFunctionName = lambdas.getInvokedFunctionArnFunctionName;
const getInvokedFunctionNameWithAlias = lambdas.getInvokedFunctionNameWithAliasOrVersion;

@@ -53,2 +54,8 @@ const samples = require('./samples');

function checkGetInvokedFunctionNameWithAliasOrVersion(functionName, functionVersion, invokedFunctionArn, expected, t) {
const awsContext = sampleAwsContext(functionName, functionVersion, invokedFunctionArn);
//console.log(`Generated AWS context = ${JSON.stringify(awsContext)}`);
t.deepEqual(getInvokedFunctionNameWithAlias(awsContext), expected, `${shorten(invokedFunctionArn)} must give ${JSON.stringify(expected)}`);
}
function checkGetAlias(functionName, functionVersion, invokedFunctionArn, expected, t) {

@@ -189,3 +196,3 @@ const awsContext = sampleAwsContext(functionName, functionVersion, invokedFunctionArn);

const expected = {functionName: '', version: '', alias: ''};
const expected = {functionName: '', version: '', alias: '', invoked: ''};
t.deepEqual(getFunctionNameVersionAndAlias(undefined), expected, `undefined context must give ${JSON.stringify(expected)}`);

@@ -195,10 +202,10 @@ t.deepEqual(getFunctionNameVersionAndAlias(null), expected, `null context must give ${JSON.stringify(expected)}`);

const expected0 = {functionName: 'test0', version: '$LATEST', alias: ''};
const expected1 = {functionName: 'test1', version: '$LATEST', alias: ''};
const expected2 = {functionName: 'test2', version: '1', alias: ''};
const expected3 = {functionName: 'test3', version: '1.0.1', alias: ''};
const expected4 = {functionName: 'test4', version: '4.0', alias: 'DEV'};
const expected5 = {functionName: 'test5', version: '5.0', alias: 'qa'};
const expected6 = {functionName: 'test6', version: '6.0', alias: 'prod'};
const expected7 = {functionName: 'test7', version: '7.0', alias: 'BETA'};
const expected0 = {functionName: 'test0', version: '$LATEST', alias: '', invoked: 'helloworld'};
const expected1 = {functionName: 'test1', version: '$LATEST', alias: '', invoked: 'helloworld:$LATEST'};
const expected2 = {functionName: 'test2', version: '1', alias: '', invoked: 'helloworld:1'};
const expected3 = {functionName: 'test3', version: '1.0.1', alias: '', invoked: 'helloworld:1.0.1'};
const expected4 = {functionName: 'test4', version: '4.0', alias: 'DEV', invoked: 'helloworld:DEV'};
const expected5 = {functionName: 'test5', version: '5.0', alias: 'qa', invoked: 'helloworld:qa'};
const expected6 = {functionName: 'test6', version: '6.0', alias: 'prod', invoked: 'helloworld:prod'};
const expected7 = {functionName: 'test7', version: '7.0', alias: 'BETA', invoked: 'helloworld:BETA'};

@@ -223,3 +230,3 @@ checkGetFunctionNameVersionAndAlias('test0', '$LATEST', arn0, expected0, t);

const expected = {functionName: name, version: version, alias: ''};
const expected = {functionName: name, version: version, alias: '', invoked: ''};
t.deepEqual(getFunctionNameVersionAndAlias(undefined), expected, `undefined context must give ${JSON.stringify(expected)}`);

@@ -229,10 +236,10 @@ t.deepEqual(getFunctionNameVersionAndAlias(null), expected, `null context must give ${JSON.stringify(expected)}`);

const expected0 = {functionName: name, version: version, alias: ''};
const expected1 = {functionName: name, version: version, alias: ''};
const expected2 = {functionName: name, version: version, alias: ''};
const expected3 = {functionName: name, version: version, alias: ''};
const expected4 = {functionName: name, version: version, alias: 'DEV'};
const expected5 = {functionName: name, version: version, alias: 'qa'};
const expected6 = {functionName: name, version: version, alias: 'prod'};
const expected7 = {functionName: name, version: version, alias: 'BETA'};
const expected0 = {functionName: name, version: version, alias: '', invoked: 'helloworld'};
const expected1 = {functionName: name, version: version, alias: '', invoked: 'helloworld:$LATEST'};
const expected2 = {functionName: name, version: version, alias: '', invoked: 'helloworld:1'};
const expected3 = {functionName: name, version: version, alias: '', invoked: 'helloworld:1.0.1'};
const expected4 = {functionName: name, version: version, alias: 'DEV', invoked: 'helloworld:DEV'};
const expected5 = {functionName: name, version: version, alias: 'qa', invoked: 'helloworld:qa'};
const expected6 = {functionName: name, version: version, alias: 'prod', invoked: 'helloworld:prod'};
const expected7 = {functionName: name, version: version, alias: 'BETA', invoked: 'helloworld:BETA'};

@@ -274,1 +281,54 @@ checkGetFunctionNameVersionAndAlias('test0', '$LATEST', arn0, expected0, t);

});
// =====================================================================================================================
// Tests for getInvokedFunctionNameWithAliasOrVersion
// =====================================================================================================================
test('getInvokedFunctionNameWithAliasOrVersion WITHOUT process.env.AWS_LAMBDA_FUNCTION_NAME/_VERSION', t => {
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
delete process.env.AWS_LAMBDA_FUNCTION_VERSION;
const expected = '';
t.deepEqual(getInvokedFunctionNameWithAlias(undefined), expected, `undefined context must give ${JSON.stringify(expected)}`);
t.deepEqual(getInvokedFunctionNameWithAlias(null), expected, `null context must give ${JSON.stringify(expected)}`);
t.deepEqual(getInvokedFunctionNameWithAlias({}), expected, `{} context must give ${JSON.stringify(expected)}`);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '$LATEST', arn0, 'helloworld', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '$LATEST', arn1, 'helloworld:$LATEST', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '1', arn2, 'helloworld:1', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '1.0.1', arn3, 'helloworld:1.0.1', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '4.0', arn4, 'helloworld:DEV', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '5.0', arn5, 'helloworld:qa', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '6.0', arn6, 'helloworld:prod', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '7.0', arn7, 'helloworld:BETA', t);
t.end();
});
test('getInvokedFunctionNameWithAliasOrVersion WITH process.env.AWS_LAMBDA_FUNCTION_NAME/_VERSION', t => {
try {
const name = 'test9999';
const version = '123.456.789';
process.env.AWS_LAMBDA_FUNCTION_NAME = name;
process.env.AWS_LAMBDA_FUNCTION_VERSION = version;
const expected = '';
t.deepEqual(getInvokedFunctionNameWithAlias(undefined), expected, `undefined context must give ${JSON.stringify(expected)}`);
t.deepEqual(getInvokedFunctionNameWithAlias(null), expected, `null context must give ${JSON.stringify(expected)}`);
t.deepEqual(getInvokedFunctionNameWithAlias({}), expected, `{} context must give ${JSON.stringify(expected)}`);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '$LATEST', arn0, 'helloworld', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '$LATEST', arn1, 'helloworld:$LATEST', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '1', arn2, 'helloworld:1', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '1.0.1', arn3, 'helloworld:1.0.1', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '4.0', arn4, 'helloworld:DEV', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '5.0', arn5, 'helloworld:qa', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '6.0', arn6, 'helloworld:prod', t);
checkGetInvokedFunctionNameWithAliasOrVersion('helloworld', '7.0', arn7, 'helloworld:BETA', t);
t.end();
} finally {
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
delete process.env.AWS_LAMBDA_FUNCTION_VERSION;
}
});

@@ -87,3 +87,4 @@ 'use strict';

* @property {string} version - the version of the Lambda function
* @property {string|undefined} [alias] - the alias of the Lambda function
* @property {string} alias - the alias of the Lambda function (if any); otherwise an empty string
* @property {string} invoked - a concatenation of the invoked function name and the invoked alias or version (if any) separated by a colon, which were extracted from the AWS Lambda's context's invoked function ARN
*/

@@ -96,3 +97,3 @@

* @property {AWSContext} awsContext - the AWS context passed to your Lambda function on invocation
* @property {LambdaFunctionNameVersionAndAlias|undefined} invokedLambda - the name, version & alias of the invoked Lambda function
* @property {LambdaFunctionNameVersionAndAlias|undefined} [invokedLambda] - the name, version & alias of the invoked Lambda function
*/

@@ -99,0 +100,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc