【发布时间】:2018-03-22 23:25:36
【问题描述】:
我创建了一个 Lambda 函数来暂停我的自动缩放组中的“终止”过程,当我在 Lambda Node.js 代码中硬编码 ASG 名称时,该过程起作用。我需要从 CloudFormation 模板中的“ASGName”自定义资源属性中提取 ASG 名称(见下文):
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“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 的新手,因此我们将不胜感激!
谢谢
【问题讨论】:
标签: javascript node.js amazon-web-services lambda amazon-cloudformation