custom-resource-helper
TypeScript icon, indicating that this package has built-in type declarations

1.0.15 • Public • Published

custom-resource-helper

Build Status

A helper for cloudformation custom resources

Install

npm install --save custom-resource-helper

How to use

import { customResourceHelper, ResourceHandler, ResourceHandlerReturn } from 'custom-resource-helper';

export const handler = customResourceHelper(
  (): ResourceHandler => ({
    onCreate: async (event, context, logger): Promise<ResourceHandlerReturn> => {
      // Place your code to handle Create events here.
      const physicalResourceId = 'myResourceId';
      const responseData = {};

      return {
        physicalResourceId,
        responseData
      };
    },
    onUpdate: async (event, context, logger): Promise<ResourceHandlerReturn> => {
      // Place your code to handle Update events here.
      const physicalResourceId = event.PhysicalResourceId;
      const responseData = {};

      return {
        physicalResourceId,
        responseData
      };
    },
    onDelete: async (event, context, logger): Promise<void> => {
      // Place your code to handle Delete events here
      return;
    }
  })
  /* optional: customLogFactory */
);

Logging

By default log level is set to warning. This can be customized with a custom LogFactory or by defining the "LogLevel" property in the custom resource resource in your template. For example:

"MyCustomResource": {
    "Type": "AWS::CloudFormation::CustomResource",
    "Properties": {
        "LogLevel": "debug",
        //...
    }
}

Utils

import { camelizeKeys } from 'custom-resource-helper';
//...
console.log(event);
/*
{
  ...
  ResourceProperties: {
    ...
    BucketName: 'testbucket',
    ---
  }
  ...
}
*/
const {
  resourceProperties: { bucketName }
} = camelizeKeys(event);

console.log(bucketName); //prints: testBuckets
//...

/custom-resource-helper/

    Package Sidebar

    Install

    npm i custom-resource-helper

    Weekly Downloads

    1,650

    Version

    1.0.15

    License

    MIT

    Unpacked Size

    27.6 kB

    Total Files

    11

    Last publish

    Collaborators

    • hupe1980