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.
yarn add --dev @reapit-cdk/custom-resource-wrapper
# or
npm install @reapit-cdk/custom-resource-wrapper --save-devimport { 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)
},
})