我创建了一个Lambda函数来暂挂我的自动调节组中的“终止”进程,该进程在Lambda Node.js代码中对ASG名称进行硬编码时起作用。我需要在CloudFormation模板从“ASGName”自定义资源属性拉ASG名称(见下文):从Node.js Lambda函数引用CloudFormation变量
SuspendProcess:
Type: Custom::SuspendProcess
Properties:
ServiceToken: arn:aws:lambda:eu-west-1:############:function:TestFunction
Region: !Ref AWS::Region
ASGName: !Ref ASG
DependsOn: "ASG"
我如何告诉Node.js的功能拉从CloudFormation的ASG名“ASGName “上面的财产?
这是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,所以任何帮助,将不胜感激!
感谢
感谢您的答复。我已经重写了现在可以工作的代码。它使用以下语法提取值:var ASGName(event.ResourceProperties.ASGName); – sharksdev