Skip to content

Latest commit

 

History

History
810 lines (598 loc) · 23.1 KB

README.md

File metadata and controls

810 lines (598 loc) · 23.1 KB

Table of Contents

DynamodbDocumentClient

A wrapper around AWS.DynamoDB.DocumentClient to simplify interactions

Parameters

  • options Object See below
    • options.table string The DynamoDB table name
    • options.name string The name to be used for the 'client' property on the logger (optional, default 'dynamodb-document')
    • options.hashKey string The DynamoDB table hash key.
    • options.rangeKey string The DynamoDB table range key (if set).
    • options.reqId string The reqId used for distributed log tracing (optional, default uuidv4())
    • options.log Object A pino compatible logger (optional, default createLogger())
    • options.params Object Additional parameters to the AWS.S3 constructor 'params' property (optional, default {})

EventbridgeReponseEntry

A basic POJO encapsulating event bridge response entry

Parameters

Properties

EventbridgeClient

A wrapper around AWS.EventBridge to simplify interactions

Parameters

  • options Object See below
    • options.eventBusName string The events bus name.
    • options.name string The name to be used for the 'client' property on the logger (optional, default 'eventbridge')
    • options.reqId string The reqId used for distributed log tracing (optional, default uuidv4())
    • options.log Object A pino compatible logger (optional, default createLogger())
    • options.params Object Additional parameters to the AWS.EventBridge constructor 'params' property (optional, default {})

putEvents

Put events to the event bridge

Parameters

  • events Object The event entries to pass to eventbridge.Entries. Entry input structure is identical to the AWS Entry type, except all keys are in lower camelcase, the Detail should be a plain serializable object, and the EventBusName should be omitted. (optional, default [])
  • params Object Additional properties to pass to the eventbridge.putEvents method (optional, default {})

Returns Array<EventbridgeReponseEntry> Array of EventbridgeReponseEntry

LambdaClient

A wrapper around AWS.Lambda to simplify interactions

Parameters

  • options Object See below
    • options.arn string The ARN of the lambda to invoke
    • options.name string The name to be used for the 'client' property on the logger (optional, default 'lambda')
    • options.reqId string The reqId used for distributed log tracing (optional, default uuidv4())
    • options.log Object A pino compatible logger (optional, default createLogger())
    • options.params Object Additional parameters to the AWS.Lambda constructor 'params' property (optional, default {})

invokeJson

Invoke the lambda

Parameters

  • payload Object The object to pass as the Payload for lambdaClient.invoke
  • params Object Additional properties to the lambdaClient.invoke method (optional, default {})

Returns any The JSON parsed response from lambdaClient.invoke

S3Client

A wrapper around AWS.S3 to simplify interactions

Parameters

  • options Object See below
    • options.bucket string The s3 Bucket
    • options.name string The name to be used for the 'client' property on the logger (optional, default 's3')
    • options.reqId string The reqId used for distributed log tracing (optional, default uuidv4())
    • options.log Object A pino compatible logger (optional, default createLogger())
    • options.params Object Additional parameters to the AWS.S3 constructor 'params' property (optional, default {})

upload

upload to S3 Bucket

Parameters

  • key Object The key to pass as the Key for s3Client.upload
  • body Object The object passed as the Body for s3Client.upload
  • params Object Additional properties to the s3.upload method (optional, default {})

Returns Promise<void>

uploadJson

upload JSON to S3 Bucket

Parameters

  • key Object The key to pass to this.upload
  • body Object The object to be stringified and passed to this.upload
  • params Object Additional properties to pass to this.upload (optional, default {})

Returns Promise<void>

getObject

getObject from S3 Bucket

Parameters

  • key Object The key to pass as the Key for s3Client.getObject
  • params Object Additional properties to the s3.getObject method (optional, default {})

Returns any The Body of response from s3.getObject

getObjectJson

getObjectJson from S3 Bucket

Parameters

  • key Object The key to pass to this.getObject
  • params Object Additional properties to pass to this.getObject (optional, default {})

Returns any The JSON response from s3.getObject

listObjectVersions

listObjectVersions from S3 Bucket

Parameters

  • params Object Additional properties to pass to s3.listObjectVersions (optional, default {})

Returns any The response from s3.listObjectVersions

deleteObjects

deleteObjects from S3 Bucket

Parameters

  • params Object Properties to pass to s3.deleteObjects (optional, default {})

Returns any The response from s3.deleteObjects

SqsSendMessageResponse

A basic POJO encapsulating sent message attributes

Parameters

Properties

SqsClient

A wrapper around AWS.SQS to simplify interactions

Parameters

  • options Object See below
    • options.queueUrl string The URL for the queue
    • options.name string The name to be used for the 'client' property on the logger (optional, default 'sqs')
    • options.reqId string The reqId used for distributed log tracing (optional, default uuidv4())
    • options.log Object A pino compatible logger (optional, default createLogger())
    • options.params Object Additional parameters to the AWS.Lambda constructor 'params' property (optional, default {})

publishJson

Publish a message to SQS that will be JSON

Parameters

  • body Object The message body to be sent to SQS
  • params Object Additional properties to the sqsClient.sendMessage method (optional, default {})

Returns SqsSendMessageResponse Information about the message sent

SnsSendMessageResponse

A basic POJO encapsulating sent message attributes

Parameters

Properties

SnsClient

A wrapper around AWS.SNS to simplify interactions

Parameters

  • options Object See below
    • options.topicArn string The ARN for the topic
    • options.name string The name to be used for the 'client' property on the logger (optional, default 'sns')
    • options.reqId string The reqId used for distributed log tracing (optional, default uuidv4())
    • options.log Object A pino compatible logger (optional, default createLogger())
    • options.params Object Additional parameters to the AWS.Lambda constructor 'params' property (optional, default {})

publishJson

Publish a message to SNS that will be JSON

Parameters

  • body Object The message body to be sent to SNS
  • params Object Additional properties to the SnsClient.sendMessage method (optional, default {})

Returns SnsSendMessageResponse Information about the message sent

AppContext

The runtime context

Parameters

  • options Object See below
    • options.awsRequestId string The awsRequestId for the current invocation
    • options.eventType string A string representing the type of event
    • options.functionName string The name of the lambda function from lambda context
    • options.log object A pino compatible logger
    • options.reqId string The distributed tracing id for this invocation

Properties

  • awsRequestId string The awsRequestId for the current invocation
  • eventType string A string representing the type of event
  • functionName string The name of the lambda function from lambda context
  • log object A pino compatible logger
  • reqId string The distributed tracing id for this invocation

EventType

The different types of events that can occur

Properties

parser

Type: Function

Parameters

  • event Object The raw lambda event
  • context Object The raw lambda context

Returns any The parsed event for the processor

processor

Type: Function

Parameters

  • parsedEvent any The parsed event output from the parser

Returns any The serialized lambda response

serializer

Type: Function

Parameters

  • response any The response from the handler to be serialized for lambda response

Returns any The serialized lambda response

wrapper

Type: Function

Parameters

  • response processor The response from the handler to be serialized for lambda response

Returns Function The processor wrapped in any additional code you may want

createContainer

Type: Function

Parameters

  • appContext AppContext The context for the current execution of the lambda
  • configuration Object The configuration object from the passed configurationRequests

Returns Object All of the side effect dependencies in an object

createProcessor

Type: Function

Parameters

  • appContext AppContext The context for the current execution of the lambda
  • container Object The response from the createContainer invocation

Returns Object All of the side effect dependencies in an object

createCache

Type: Function

Returns cacheManager An instance of cacheManager

createWrapper

Type: Function

Parameters

  • appContext AppContext The context for the current execution of the lambda
  • parser parser The parser provided to createHandler
  • serializer serializer The serializer provided to createHandler

Returns wrapper All of the side effect dependencies in an object

lambdaHandler

Type: Function

Parameters

  • event object The raw lambda event
  • context object The raw lambda context

Returns any The result of the processor

createHandler

The entry point for creating handlers

Parameters

  • options Object See below
    • options.parser parser? An optional function to parse the incoming lambda event
    • options.serializer serializer? An optional function to serialize the response from the lambda invocation
    • options.configurationRequests Array<ConfigurationRequest> An array of configuration requests to be fulfilled before each invocation of the handler (optional, default [])
    • options.createContainer createContainer A factory function that will return all needed side effect dependencies. Eg. Http (optional, default ()=>({}))
    • options.createCache createCache An instance of cacheManager. Will be used to cache configuration. (optional, default defaultCache)
    • options.createWrapper createWrapper A factory function that will return the processor wrapped in additional functionality (optional, default createDefaultWrapper)
    • options.createProcessor createProcessor A factory function that will return the main handler for the lambda
    • options.loggerOptions Object? Additional options to pass to the logger (optional, default {})
    • options.t any? For use with AVA during testing

Returns lambdaHandler A lambda handler

createJsonHandler

A handler designed for direct lambda invocations that respond with a JSON serializable object. Takes identical options as createHandler, however the serializer and parser options will always be overridden with the identity function.

Parameters

  • options any Takes identical options as createHandler, however the serializer and parser options will always be overridden with the identity function.

createApiJsonHandler

A handler designed for lambda invocations through api gateway that respond with a JSON serializable object. Takes identical options as createHandler, however the wrapper option will always be overridden with the multi-status code version.

See the following:

Parameters

  • options any Takes identical options as createHandler, however the wrapper option will always be overridden with the multi-status code version.

parseJsonHttpEvent

This parse will handle the following:

  • Body parsed into a json object
  • HTTP method as a string
  • Path parameters as key value pairs, properly decoded from uri
  • Query string parameters as multi-value entries. Object<string, Array>
  • Headers as multi-value entries. Object<string, Array>
  • Request context
  • Cookies

Parameters

  • event object An event from Api Gateway -> Lambda Proxy Integration

Returns HttpEvent The parsed event

HttpEvent

Parse an HTTP Lambda event

Parameters

  • $0 Object
    • $0.body
    • $0.httpMethod
    • $0.pathParameters
    • $0.queryStringParameters
    • $0.headers
    • $0.requestContext
    • $0.cookies
  • options Object See below
    • options.body Object The body of the event
    • options.httpMethod string String name of the http method
    • options.pathParameters Object<string, string> An object of path part name, value pairs
    • options.queryStringParameters Object<string, Array<string>> An object of parameter name, array of values pairs
    • options.headers Object<string, Array<string>> An object of header name, array of values pairs
  • requestContext Object The requestContext object

Properties

parseJsonMonoSqsEvent

Parse a Lambda SQS event

Parameters

  • sqsEvent Object A Lambda SQS event

Returns SqsEvent The parsed SQS event

SqsEvent

An SQS Event

Parameters

  • options Object See below
    • options.body Object The body of the SQS event

Properties

  • body Object The body of the event

MultiStatusJsonResponse

A json response with statusCode

Parameters

  • $0 Object
    • $0.statusCode
    • $0.body
  • statusCode number The statusCode of the response
  • body Object The json object body of the response

multiStatusCodeJsonSerializer

A serializer for handling statusCode and json object body responses

Parameters

Returns Object Api gateway compatible response with statusCode, body, and headers set appropriately

createDefaultWrapper

A wrapper that handles top level logging/parsing/serialization orchestration

Parameters

  • ctx object Internal use
  • parser (optional, default event=>event)
  • serializer (optional, default data=>data)

Returns wrapper The wrapped processor

createApiJsonWrapper

A processor that uses the provided parser and the multiStatusCodeJsonSerializer The response from the process needs to be in the form: { statusCode: [number], data: [JSON serializable object] }

Parameters

  • ctx object Internal use
  • parser (optional, default event=>event)
  • serializer (optional, default multiStatusCodeJsonSerializer)

Returns wrapper The wrapped processor

readJson

A method read a file from disk and parse it as JSON

Parameters

  • args ...any The path as it would be provided to path.resolve

Returns Object The file contents parsed as JSON

LOGGER_REDACTION_LISTS

A collection of logger redactions for common sensitive property paths.