You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Node.js 6.10版AWS Lambda函数遇cfn-response模块找不到错误求助

Hey there, let's work through that Cannot find module 'cfn-response' error you're seeing in your Node.js 6.10 Lambda function (using the online editor). Here are the most common fixes to try:

1. Confirm if you actually need the cfn-response module

The cfn-response module is only meant for Lambda functions that act as CloudFormation Custom Resources. If your function isn't tied to a CloudFormation stack's custom resource (e.g., it's just a regular Lambda triggered by API Gateway, S3, etc.), you don't need this module at all—just delete the require('cfn-response') line, and that error should go away.

2. Manually implement the cfn-response logic (most reliable fix)

Even if you are using the function for CloudFormation custom resources, sometimes the runtime's built-in cfn-response module can be finicky in older Node.js versions like 6.10. Instead of relying on it, just copy the module's source code directly into your function. This removes any dependency on the Lambda environment's built-in files.

Add this code at the top of your Lambda handler file:

const https = require('https');
const url = require('url');

function send(event, context, responseStatus, responseData, physicalResourceId) {
    const responseBody = JSON.stringify({
        Status: responseStatus,
        Reason: `Check CloudWatch Log Stream: ${context.logStreamName}`,
        PhysicalResourceId: physicalResourceId || context.logStreamName,
        StackId: event.StackId,
        RequestId: event.RequestId,
        LogicalResourceId: event.LogicalResourceId,
        Data: responseData
    });

    const parsedUrl = url.parse(event.ResponseURL);
    const options = {
        hostname: parsedUrl.hostname,
        port: 443,
        path: parsedUrl.path,
        method: 'PUT',
        headers: {
            'Content-Type': '',
            'Content-Length': responseBody.length
        }
    };

    const request = https.request(options, () => {
        context.done();
    });

    request.on('error', (err) => {
        context.fail(err);
    });

    request.write(responseBody);
    request.end();
}

exports.send = send;

Then, instead of importing the external module, just use the local send function directly (or import it from your handler file if you split code). This works exactly like the official cfn-response module, but without the environment dependency.

3. Double-check your require statement

It sounds silly, but typos happen all the time! Make sure your line is exactly:

const cfnResponse = require('cfn-response');

No capital letters, no missing hyphens—Node.js module names are case-sensitive.

4. Quick sanity check for CloudFormation custom resources

If you are using this for a CloudFormation custom resource, ensure your Lambda execution role has the cloudformation:SignalResource permission. This won't fix the "module not found" error, but it's a common follow-up issue once you resolve the module problem.

内容的提问来源于stack exchange,提问作者SanityCheck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:27:19