Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @middy/s3-key-normalizer with all npm packages installed. Try it out:

require("@middy/core/package.json"); // @middy/core is a peer dependency. var s3KeyNormalizer = require("@middy/s3-key-normalizer")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@middy/s3-key-normalizer v1.1.0

S3 key normalizer middleware for the middy framework

Middy s3-key-normalizer middleware

Middy logo

S3 key normalizer middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

Normalizes key names in s3 events.

S3 events like S3 PUT and S3 DELETE will contain in the event a list of the files that were affected by the change.

In this list the file keys are encoded in a very peculiar way (urlencoded and space characters replaced by a +). Very often you will use the key directly to perform operations on the file using the AWS S3 SDK, in which case it's very easy to forget to decode the key correctly.

This middleware, once attached, makes sure that every S3 event has the file keys properly normalized.

Install

To install this middleware you can use NPM:

npm install --save @middy/s3-key-normalizer

Options

This middleware does not have any option

Sample usage

const middy = require('@middy/core')
const s3KeyNormalizer = require('@middy/s3-key-normalizer')

const handler = middy((event, context, cb) => {
  // use the event key directly without decoding it
  console.log(event.Records[0].s3.object.key)

  // return all the keys
  callback(null, event.Records.map(record => record.s3.object.key))
})

handler
  .use(s3KeyNormalizer())

Middy documentation and examples

For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.

Contributing

Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

License

Licensed under MIT License. Copyright (c) 2017-2018 Luciano Mammino and the Middy team.

FOSSA Status

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free