1.0.2 • Published 4 years ago

aws-lambda-context-mock v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

AWS Lambda Context Mock

Docs: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-context.html

When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment.

Usage

import { awsLambdaContextMock } from 'aws-lambda-context-mock';

//... default mock
test(`handler redirects uri to '/index.html'`, () => {
  // invoke lambda handler
  handler(event, awsLambdaContextMock(), cb);
  /// ...
});

//... custom, mock
test(`handler redirects uri to '/index.html'`, () => {
  // invoke lambda handler
  handler(
    event,
    awsLambdaContextMock({ callbackWaitsForEmptyEventLoop: true }),
    cb
  );
  /// ...
});

Context methods (with mock defaults)

NameTypeDefaultDescription
getRemainingTimeInMillis() => number() => 500Returns the number of milliseconds left before the execution times out

Context properties

NameTypeDefaultDescription
getRemainingTimeInMillis() => number() => 500Returns the number of milliseconds left before the execution times out
functionNamestringviewer-requestThe name of the Lambda function.
functionVersionstring1234The version of the function.
invokedFunctionArnstringfakearnThe Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a version number or alias.
memoryLimitInMBstring5000The amount of memory that's allocated for the function.
awsRequestIdstring1234The identifier of the invocation request.
logGroupNamestringgroupnameThe log group for the function.
logStreamNamestringstreamnameThe log stream for the function instance.
identityCognitoIdentity{ cognitoIdentityId: '12345', cognitoIdentityPoolId: '45678' }(mobile apps) Information about the Amazon Cognito identity that authorized the request. cognitoIdentityId - The authenticated Amazon Cognito identity. cognitoIdentityPoolId - The Amazon Cognito identity pool that authorized the invocation.
clientContextClientContext{"clientContext":{"client":{"installationId":"123456","appTitle":"app","appVersionName":"v2","appVersionCode":"000","appPackageName":"pkg"},"Custom":{"custom":"12345"},"env":{"platformVersion":"12345","platform":"12345","make":"12345","model":"12345","locale":"de"}}}(mobile apps) Client context that's provided to Lambda by the client application.
callbackWaitsForEmptyEventLoopbooleanfalseSet to false to send the response right away when the callback executes, instead of waiting for the Node.js event loop to be empty. If this is false, any outstanding events continue to run during the next invocation.

Embedded types

export interface CognitoIdentity {
  cognitoIdentityId: string;
  cognitoIdentityPoolId: string;
}

export interface ClientContext {
  client: ClientContextClient;
  Custom?: any;
  env: ClientContextEnv;
}

export interface ClientContextClient {
  installationId: string;
  appTitle: string;
  appVersionName: string;
  appVersionCode: string;
  appPackageName: string;
}

export interface ClientContextEnv {
  platformVersion: string;
  platform: string;
  make: string;
  model: string;
  locale: string;
}