[英]Referencing CloudFormation variable from a Node.js Lambda function
我創建了一個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的新手,所以我們將不勝感激!
謝謝
建議不要使用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
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.