Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading "WARNING: Both Xxx and AsyncXxx handlers defined. Ignoring AsyncXxx" logged #53

Open
ankon opened this issue Apr 21, 2021 · 0 comments

Comments

@ankon
Copy link

ankon commented Apr 21, 2021

Assume the following code for a custom resource function:

const CfnLambdaFactory = require('cfn-lambda');

exports.handler = CfnLambdaFactory({
  AsyncCreate: /* Valid async create handler */,
  AsyncUpdate: /* Valid async update handler */,
  AsyncDelete: /* Valid async delete handler */,
  Schema: /* Valid schema */
});

If this is executed for the first time, everything is fine. But, when executing it again, and there is a cached execution environment in AWS' Lambda execution environment already, the second execution will log warnings like this:

2021-04-21T11:26:02.545Z	9c68dea6-3a26-4ca5-88a7-cdb011eb06fe	INFO	WARNING: Both Create and AsyncCreate handlers defined. Ignoring AsyncCreate
2021-04-21T11:26:02.545Z	9c68dea6-3a26-4ca5-88a7-cdb011eb06fe	INFO	WARNING: Both Update and AsyncUpdate handlers defined. Ignoring AsyncUpdate
2021-04-21T11:26:02.545Z	9c68dea6-3a26-4ca5-88a7-cdb011eb06fe	INFO	WARNING: Both Delete and AsyncDelete handlers defined. Ignoring AsyncDelete

These warnings are misleading: There's nothing wrong really with the resource definition, but rather due to the caching the resource definition is now wrong. The first execution has added the Create, Update, and Delete definitions to it.

For quick reference:

cfn-lambda/index.js

Lines 34 to 50 in 8bad51a

function CfnLambdaFactory(resourceDefinition) {
return function CfnLambda(event, context) {
// support Async handler functions:
if(resourceDefinition.AsyncCreate) {
if(resourceDefinition.Create) {
console.log('WARNING: Both Create and AsyncCreate handlers defined. Ignoring AsyncCreate')
} else {
resourceDefinition.Create = function(CfnRequestParams, reply) {
return ReplyAfterHandler(
resourceDefinition.AsyncCreate(CfnRequestParams), reply
)
}
}
}

I could see these options to fix this:

  1. delete the AsyncCreate, AsyncUpdate, and AsyncDelete properties after adding the wrappers. This would change a parameter though, so as developer I would not expect this unless there's a huge warning somewhere in the docs. But ...
  2. First create a copy of the resource definition, before modifying it would fix that.
  3. Alternatively, and my preferred approach: Move the check and creation of the wrappers BEFORE the return function CfnLambda, so that these only get executed on the first call.

WDYT?

Also: Regardless of which fix is chosen, it would be nice to move from console.log('WARNING: ...') to console.warn('...') :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant