Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Node.js Lambda函数引用CloudFormation变量_Javascript_Node.js_Amazon Web Services_Lambda_Amazon Cloudformation - Fatal编程技术网

Javascript 从Node.js Lambda函数引用CloudFormation变量

Javascript 从Node.js Lambda函数引用CloudFormation变量,javascript,node.js,amazon-web-services,lambda,amazon-cloudformation,Javascript,Node.js,Amazon Web Services,Lambda,Amazon Cloudformation,我已经创建了一个Lambda函数来挂起我的自动缩放组中的“终止”进程,当我在Lambda Node.js代码中硬编码ASG名称时,该进程就会工作。我需要从CloudFormation模板中的“ASGName”自定义资源属性中提取ASG名称(请参见下文): 如何告诉node.js函数从上面的CloudFormation“ASGName”属性中提取ASG名称 这是node.js函数代码: var AWS = require('aws-sdk'); var uuid = require('uuid')

我已经创建了一个Lambda函数来挂起我的自动缩放组中的“终止”进程,当我在Lambda Node.js代码中硬编码ASG名称时,该进程就会工作。我需要从CloudFormation模板中的“ASGName”自定义资源属性中提取ASG名称(请参见下文):

如何告诉node.js函数从上面的CloudFormation“ASGName”属性中提取ASG名称

这是node.js函数代码:

var AWS = require('aws-sdk');
var uuid = require('uuid');
AWS.config.update({ region: 'eu-west-1' });

exports.handler = (event, context, callback) => {

AWS.config.apiVersions = {
  autoscaling: '2011-01-01',
};

var autoscaling = new AWS.AutoScaling();
var ASGName = parseInt(event.ResourceProperties.ASGName);

/* This suspends the specified scaling process for the specified Auto 
Scaling group. */

 var params = {
  AutoScalingGroupName: "ASGName", 
  ScalingProcesses: [
     "Terminate"
  ]
 };
 autoscaling.suspendProcesses(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
 });
};
我尝试创建一个变量=ASGName来指向CloudFormation属性,然后将其引用为AutoscalingGroupName。我知道这里的语法不正确。我见过很多例子,但都不管用

我是Node.js的新手,因此任何帮助都将不胜感激


谢谢

我建议您使用nodeJS sdk代码获取该资源,然后将该信息放入
ASGName
变量中,而不是尝试在属性中获取它

var params = {
  LogicalResourceId: 'STRING_VALUE', /* required */
  StackName: 'STRING_VALUE' /* required */
};
cloudformation.describeStackResource(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     ASGName = data;           // successful response
});

我建议您使用nodeJS sdk代码获取该资源,然后将该信息放入
ASGName
变量中,而不是尝试在属性中获取它

var params = {
  LogicalResourceId: 'STRING_VALUE', /* required */
  StackName: 'STRING_VALUE' /* required */
};
cloudformation.describeStackResource(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     ASGName = data;           // successful response
});

感谢您的回复。我已经重写了代码,现在可以工作了。它使用以下语法提取值:var ASGName(event.ResourceProperties.ASGName);谢谢你的回复。我已经重写了代码,现在可以工作了。它使用以下语法提取值:var ASGName(event.ResourceProperties.ASGName);