Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.5 KB

File metadata and controls

45 lines (36 loc) · 1.5 KB

@reapit-cdk/custom-resource-wrapper

npm version npm downloads coverage: 99.02%25

This module helps write custom resource handlers. It's designed to work with the Custom Resource Provider Framework. It accepts an object which contains event handlers for onCreate, and optionally, onUpdate, and onDelete. Anything returned from onCreate and onUpdate is returned as data attributes on the resulting custom resource.

Package Installation:

yarn add --dev @reapit-cdk/custom-resource-wrapper
# or
npm install @reapit-cdk/custom-resource-wrapper --save-dev

Usage

import { customResourceWrapper } from '@reapit-cdk/custom-resource-wrapper'

import { createThing, deleteThing } from './your-module'

export const onEvent = customResourceWrapper({
  onCreate: async ({ aProperty }) => {
    const { aDataAttribute } = await createThing(aProperty)
    return {
      aDataAttribute,
    }
  },
  onUpdate: async ({ aProperty }, oldProps) => {
    if (aProperty !== oldProps.aProperty) {
      await deleteThing(oldProps.aProperty)
      const { aDataAttribute } = await createThing(aProperty)
      return {
        aDataAttribute,
      }
    }
  },
  onDelete: async ({ aProperty }) => {
    await deleteThing(aProperty)
  },
})