moromi-aws-lambda

aws lambda plugin for moromi

Usage no npm install needed!

<script type="module">
  import moromiAwsLambda from 'https://cdn.skypack.dev/moromi-aws-lambda';
</script>

README

moromi-aws-lambda

aws lambda plugin for moromi

Installation

  yarn add moromi-aws-lambda

Usage

params:

  • module: the local filename of the lambda module to test (relative to the folder where moromi is being called from)
  • handler (default handler): the handler name exported by the lambda module
  • event (default {}): the event that the handler should be called with
  • context (default null): the context that the handler should be called with

Example

Given the following lambda function:

module.exports.handler = ({ Records: [{ cf: { request: {
  uri, method = 'GET', querystring = '', headers
} } }] }, context, callback) => callback(null, {
  uri,
  method,
  headers
});

the following moromi test will pass:

{
  name: 'example aws lambda test',
  type: require('moromi-aws-lambda')
  params: {
    module: '../index.js',
    event: {
      Records: [{ cf: { request: {
        uri: '/test',
        headers: {
          host: [{ key: 'Host', value: 'example.is' }]
        }
      } } }]
    }
  },
  expected: {
    uri: '/test', method: 'GET',
   'headers.host.0.value': 'example.is'
  }
}