Referencing CloudFormation variable from a Node.js Lambda function

I've created a Lambda function to suspend the "Terminate" process in my autoscaling group which works when I hardcode the ASG Name in the Lambda Node.js code. I need to pull the ASG name from the "ASGName" custom resource property in the CloudFormation Template (see below):

 Type: Custom::SuspendProcess
   ServiceToken: arn:aws:lambda:eu-west-1:############:function:TestFunction
   Region: !Ref AWS::Region
   ASGName: !Ref ASG
 DependsOn: "ASG" 

How do I tell the node.js function to pull the ASG name from the CloudFormation "ASGName" property above?

This is the node.js function code:

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: [
 autoscaling.suspendProcesses(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response

I've tried to create a variable = ASGName to point to the CloudFormation property then reference this as the AutoscalingGroupName. I know the syntax isn't correct here. I've seen lots of examples but none of them work.

I'm new to Node.js so any help would be appreciated!


1 answer