Javascript 什么';从Lambda函数中更新CloudFormation堆栈的正确方法是什么?

Javascript 什么';从Lambda函数中更新CloudFormation堆栈的正确方法是什么?,javascript,amazon-web-services,aws-lambda,amazon-cloudformation,Javascript,Amazon Web Services,Aws Lambda,Amazon Cloudformation,到目前为止,我的代码如下所示: const AWS = require('aws-sdk'); AWS.config.update({ region: 'eu-west-1' }); const CF = new AWS.CloudFormation({ apiVersion: '2010-05-15' }); const updateParams = { StackName: myStackName, UsePreviousTemplate: true, Parameters:

到目前为止,我的代码如下所示:

const AWS = require('aws-sdk');
AWS.config.update({ region: 'eu-west-1' });
const CF = new AWS.CloudFormation({ apiVersion: '2010-05-15' });

const updateParams = {
  StackName: myStackName,
  UsePreviousTemplate: true,
  Parameters: [
    {
    ParameterKey: "StackOffline",
    ParameterValue: "Online"
    }
  ],
  Capabilities: [
    "CAPABILITY_IAM",
    "CAPABILITY_AUTO_EXPAND"
  ]
};

exports.handler = async (event) => {    
    CF.updateStack(updateParams, (err, data) => {
      if (err)
        console.log(err, err.stack);
      else
        console.log(data);
    });
    
    // ...
};
问题是。。。它没有任何作用。当它运行时,它实际上不会记录任何东西;没有
数据
,也没有错误消息

我尝试使用堆栈名和唯一的堆栈ID,但两者都不起作用

最后,我保存了
updateStack()
的返回值(
Request
,我想),下面是它的
response
属性:

response: Response {
  request: [Circular *1],
  data: null,
  error: null,
  retryCount: 0,
  redirectCount: 0,
  httpResponse: HttpResponse {
    statusCode: undefined,
    headers: {},
    body: undefined,
    streaming: false,
    stream: null,
    _abortCallback: [Function: callNextListener]
  },
  maxRetries: 3,
  maxRedirects: 10
}
(如果需要,我也可以发布整个
请求
。我没有发布,因为它太大了,我不知道它是否包含任何敏感信息。)


我假设那些
null
值是一个问题。我哪里出错了?

您遇到了一个古老的
异步/await
回调
问题。太长,读不下去了不要把它们结合起来

对于非异步处理程序,函数执行将继续,直到事件循环为空或函数超时。在所有事件循环任务完成之前,不会将响应发送到调用程序。如果函数超时,则返回一个错误。您可以通过将context.callbackhaitsforemptyeventloop设置为false,将运行时配置为立即发送响应

将代码改为类似以下内容:

const AWS=require('AWS-sdk');
AWS.config.update({地区:'eu-west-1'});
const CF=新的AWS.CloudFormation({apiVersion:'2010-05-15'});
常数更新图={
StackName:myStackName,
UsePreviousTemplate:true,
参数:[
{
ParameterKey:“StackOffline”,
参数值:“在线”
}
],
能力:[
“能力”,
“功能自动扩展”
]
};
exports.handler=异步(事件)=>{
试一试{
const data=await CF.updateStack(updateParams.promise();
控制台日志(数据);
// ...
}
捕捉(错误){
日志(err,err.stack);
}    
};