question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find module 'cfn-response': AWS Lambda nodejs10.x

See original GitHub issue

Confirm by changing [ ] to [x] below to ensure that it’s a bug:

Describe the bug When updating my Lambda functions from nodejs8.10 to nodejs10.x - as per request from AWS Lambda operational notification - I get the error “Cannot find module ‘cfn-response’”, which completely breaks my CloudFormation deployment. If I rollback the same deployed lambda to nodejs8.10 it works again.

Is the issue in the browser/Node.js? AWS Labmda using Node.js 10.x

If on Node.js, are you running this on AWS Lambda? Yes!

Details of the browser/Node.js version nodejs10.x

SDK version number The one used by AWS Lambda - I guess always the latest.

To Reproduce (observed behavior)

var cfnresp = require('cfn-response')

exports.handler = async (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

Expected behavior

Response:
{
  "statusCode": 200,
  "body": "\"Hello from Lambda!\""
}

Request ID:
"565f6238-fd8c-4b9c-bfab-bebca1dd0e2d"

Screenshots

Response:
{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'cfn-response'",
  "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module 'cfn-response'",
    "    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:45:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:778:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
    "    at Module.load (internal/modules/cjs/loader.js:653:32)",
    "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
    "    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)",
    "    at startup (internal/bootstrap/node.js:283:19)"
  ]
}

Request ID:
"f5fe7e20-65c6-4cb6-adb2-e2a80bfb9968"

Function Logs:
START RequestId: f5fe7e20-65c6-4cb6-adb2-e2a80bfb9968 Version: $LATEST
2019-11-14T04:27:27.919Z	undefined	ERROR	Uncaught Exception	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'cfn-response'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'cfn-response'","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:45:30)","    at Module._compile (internal/modules/cjs/loader.js:778:30)","    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)","    at Module.load (internal/modules/cjs/loader.js:653:32)","    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)","    at Function.Module._load (internal/modules/cjs/loader.js:585:3)","    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)","    at startup (internal/bootstrap/node.js:283:19)"]}
END RequestId: f5fe7e20-65c6-4cb6-adb2-e2a80bfb9968
REPORT RequestId: f5fe7e20-65c6-4cb6-adb2-e2a80bfb9968	Duration: 1905.42 ms	Billed Duration: 2000 ms	Memory Size: 128 MB	Max Memory Used: 24 MB	
Unknown application error occurred
Runtime.ImportModuleError

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
RLThomazcommented, Nov 14, 2019

It seems that in Node.js 10.x we need to specify the relative path to actually find cfn-response. So this code snipet below should work just fine:

var cfnresp = require('./cfn-response')

exports.handler = async (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

If that is the issue/solution, can you please close this ticket and update the documentation? The documentation actually tells us to use it like the first example.

Editing: I have one more concern.

So cfn-response is basically required for CloudFormation, hence the name. How does CloudFormation “ZipFile” - under the Lambda resource - actually knows when to upload cfn-response.js? Is it also going to upload it when we require it as './cfn-response'?

2reactions
prashantalhatcommented, Nov 20, 2019

thanks @RLThomaz you saved my day. I was facing this issue when updating my nodejs runtime from 8 to 10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Lambda Node.js 6.10 : "errorMessage": "Cannot find ...
I am trying to deploy a lambda function in Nodejs 6.10 and I am getting ... Response: { "errorMessage": "Cannot find module 'cfn-response'", ......
Read more >
cfn-response module - AWS CloudFormation
The module contains a send method, which sends a response object to a custom resource by way of an Amazon S3 presigned URL...
Read more >
Cannot find module (AWS Lambda Error) [Solved] | bobbyhadz
A complete step-by-step guide on how to solve the "Cannot find module" error when trying to load third party packages in AWS lambda....
Read more >
Invoking AWS Lambda function from a nodejs proxy,C...
We are trying to invoke a Lambda function from a node.js API proxy. The test seems to fail with a aws-sdk module not...
Read more >
How to Solve a AWS Lambda error - Runtime.ImportModuleError
ImportModuleError: Error: Cannot find module 'jmespath' ... You run the same scripts via AWS Lambda nodejs10 or nodejs12 environment and may ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found