5.0.16 • Published 5 months ago

cfn-custom-resource v5.0.16

Weekly downloads
398
License
MIT
Repository
github
Last release
5 months ago

Cloudformation Custom Resources Helper

Node.js module providing utility functions and constants for AWS CloudFormation Custom Resources.

npm main JavaScript Style Guide

Supported Runtimes

  • NodeJS 10+  

Usage

const cfnCR = require('cfn-custom-resource');
const { configure, sendSuccess, sendFailure, sendResponse, LOG_VERBOSE, SUCCESS } = cfnCR;

/* Increase the logging level */
configure({ logLevel: LOG_VERBOSE });

/**
  Do resource creation
                      **/

/* Resource successfully created! - async/await */
const result = await sendSuccess(id, { ImportantInfo: otherId }, event);
return result;

/* Resource successfully created! - Promises */
return sendSuccess(id, { ImportantInfo: otherId} , event, callback);

/* Resource encountered an error during creation - async/await */
await sendFailure('mistakes were made', event); // Simple form
await sendFailure('mistakes were made', event, null, null, id); //If there's a special resource id to pass

/* Resource encountered an error during creation - Promises */
return sendFailure('mistakes were made', event, callback); // Simple form
return sendFailure('mistakes were made', event, callback, null, id); //If there's a special resource id to pass

/* If you want full control */
await sendResponse({ Status: SUCCESS, PhysicalResourceId: id, Data: { ImportantInfo: otherId } }, event);

Constants

  • Responses - SUCCESS and FAILED
  • Request Types - CREATE, UPDATE, DELETE
  • Logging Levels - LOG_NORMAL, LOG_VERBOSE, LOG_DEBUG
  • Default sendFailure text - DEFAULT_PHYSICAL_RESOURCE_ID, DEFAULT_REASON_WITH_CONTEXT, DEFAULT_REASON (no context)  

Functions

configure(options) ⇒ void

Configures the module with the given options

Kind: global function
Returns: void - Void return

ParamTypeDescription
optionsObjectOptions to configure with

sendResponse(responseDetails, event, callback) ⇒ Promise

Sends a response to Cloudformation about the success or failure of a custom resource deploy

Kind: global function
Returns: Promise - Promise for sending the response. If the Lambda callback is provided,returns the provided callback with error/result parameters. If the Lambda callback is not provided, returns the error or result data directly. Errors are returned for FAILED responses as well as for any errors in the send response execution. If Data is provided, it is provided as the callback result or returned directly. Otherwise, null will be provided as the callback result or returned directly.

ParamTypeDescription
responseDetailsObjectContains the properties for the response
responseDetails.StatusstringStatus for the response. SUCCESS or FAILED.
responseDetails.ReasonstringReason for FAILED response. Ignored if SUCCESS.
responseDetails.PhysicalResourceIdstringPhysical resource id
responseDetails.DatastringAdditional response to return. Optional.
eventObjectLambda event that contains passthrough information
callbackfunctionOptional. Lambda callback.

sendSuccess(physicalResourceId, data, event, callback) ⇒ Promise

Sends a success response to Cloudformation. Wraps sendResponse.

Kind: global function
Returns: Promise - Promise for sending the response If the Lambda callback is provided,returns the provided callback with error/result parameters. If the Lambda callback is not provided, returns the error or result data directly. Errors are returned for FAILED responses as well as for any errors in the send response execution. If Data is provided, it is provided as the callback result or returned directly. Otherwise, null will be provided as the callback result or returned directly.

ParamTypeDescription
physicalResourceIdstringPhysical Resource Id of the resource
data*Optional. Additional data to send. If not an object, it is wrapped in one with a single property, data, assigned to it.
eventObjectLambda event
callbackfunctionLambda callback

sendFailure(reason, event, callback, context, physicalResourceId) ⇒ Promise

Sends a failed response to Cloudformation. Wraps sendResponse.

Kind: global function
Returns: Promise - Promise for sending the responses If the Lambda callback is provided,returns the provided callback with error/result parameters. If the Lambda callback is not provided, returns the error or result data directly. Errors are returned for FAILED responses as well as for any errors in the send response execution. If Data is provided, it is provided as the callback result or returned directly. Otherwise, null will be provided as the callback result or returned directly.

ParamTypeDescription
reasonstringReason for the failure. If not provided, a default is provided.
eventObjectLambda event
callbackfunctionLambda callback
contextObjectLambda context. Used for providing a useful default reason.
physicalResourceIdstringPhysical Resource Id of the resource. If not provided, uses the one from the event. If none in the event, generates one.
5.0.15

5 months ago

5.0.16

5 months ago

5.0.14

3 years ago

5.0.13

3 years ago

5.0.12

3 years ago

5.0.11

3 years ago

5.0.10

4 years ago

5.0.9

4 years ago

5.0.8

4 years ago

5.0.7

4 years ago

5.0.6

4 years ago

5.0.5

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.0.16

5 years ago

4.0.15

5 years ago

4.0.14

5 years ago

4.0.13

5 years ago

4.0.12

5 years ago

4.0.11

5 years ago

4.0.10

5 years ago

4.0.9

5 years ago

4.0.8

6 years ago

4.0.7

6 years ago

4.0.6

6 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.2.1

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.3

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago