15

I have a CloudFormation template that creates an auto scaling group (among other things). How can I give the auto scaling group a name in the template?
The AWS docs do not mention anything (http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html), and its possible to do if I create it trough the AWS website. (I need to give a group a name because I need to find this group from another script)

EDIT: I've tried to add a tag called "Name", but it still does not work:

"Resources": {
"MyServerGroup" : {
  "Type" : "AWS::AutoScaling::AutoScalingGroup",
  "Properties" : {
    "AvailabilityZones" : { "Fn::GetAZs" : ""},
    "LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
    "MinSize" : { "Ref" : "ServerCount" },
    "MaxSize" : { "Ref" : "ServerCount" },
    "DesiredCapacity" : { "Ref" : "ServerCount" },
    "LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancerName" } ],
    "Tags" : [ {
      "Key" : "Name",
      "Value" : { "Ref" : "ServerName" },
      "PropagateAtLaunch" : "true"
    } ]
  },
  "CreationPolicy": {
    "ResourceSignal": {
      "Count": "2",
      "Timeout": "PT5M"
    }
  }
},

The name column in the AWS console still displays something like "MyStackName-MyServerGroup-345MH3NF34N7E", and in the Tags field I can see the key-value pair for the Name tag that I added.

5 Answers 5

4

Although naming the AutoScalingGroup (ASG) doesn't seem to be possible, you can export the name assigned when the ASG is created by the CloudFormation (CF) template by using the following:

  Outputs:
  AutoScalingGroupName:
    Description: "AutoScalingGroup Name"
    Export:
      Name:
        Fn::Sub: ${AWS::StackName}-autoscalinggroupname
    Value: { Ref: AutoScalingGroup }

The ASG name can then be used in other CF templates, although this is perhaps not what the OP means by "find this group from another script".

2

CloudFormation now has a property called: AutoScalingGroupName

Description: "The name of the Auto Scaling group. Minimum length of 1. Maximum length of 255. Must follow the following pattern: [\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*" Type: String Required: No

see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html

2

Create a tag with for the ASG with the key "Name" (the capital N is important). This will be used for the Name column in the console.

Note that you could find the ASG by searching for a well known tag other than Name from your other script. Tags are a great way to search for resources.

4
  • 1
    I've tried your solution, it does not work :/ . I've added my cloudFormation template to the question.
    – sydd
    Jun 16, 2015 at 17:31
  • "Name" : "yourname" instead of "Key" : "Name"
    – Mircea
    Jun 17, 2015 at 22:52
  • 2
    I'll leave my answer for posterity, but you're right that this solution doesn't seem to work. The Name tag is ignored for AWS::AutoScaling::AutoScalingGroup resources, and AFAICT there's no substitute.
    – Ben Whaley
    Jun 18, 2015 at 2:43
  • It's a little funky, in that they overload the semantics to allow you to set tags on the instances via PropagateAtLaunch. The implication from the AWS Docs is that you should be able to name your ASG if you set it to false, but because most people have more interest in attaching names to their instances than their ASG, it's probably tied into some deeper magic that the docs don't discuss. Jul 23, 2015 at 14:29
0

Clearly from the AWS Tagging Auto Scaling Groups and Instances doc, you can not set value of tag prefixed with aws:.

I guess, value you have read from console "MyStackName-MyServerGroup-345MH3NF34N7E" is of tag aws:autoscaling:groupName. So its obvious you can not set Auto Scaling Group Name in CloudFormation Template.

Unfortunately, from my experience, you can not pass tag value in CloudFormation template. But best, you can use AWS SDK to read tag value from launched EC2 instances.

-1

The attribute "AutoscalingGroupName" within AWS::AutoScaling::AutoScalingGroup entity works.

Sample template :

"Autoscaling1"
{
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
  "AutoScalingGroupName" : String,
  "AvailabilityZones" : [ String, ... ],
  "Cooldown" : String,
  "DesiredCapacity" : String,
  "HealthCheckGracePeriod" : Integer,
  "HealthCheckType" : String,
  "InstanceId" : String,
  "LaunchConfigurationName" : String,
  "LifecycleHookSpecificationList" : [ LifecycleHookSpecification, ... ],
  "LoadBalancerNames" : [ String, ... ],
  "MaxSize" : String,
  "MetricsCollection" : [ MetricsCollection, ... ],
  "MinSize" : String,
  "NotificationConfigurations" : [ NotificationConfiguration, ... ],
  "PlacementGroup" : String,
  "Tags" : [ TagProperty, ... ],
  "TargetGroupARNs" : [ String, ... ],
  "TerminationPolicies" : [ String, ... ],
  "VPCZoneIdentifier" : [ String, ... ]
 }
}     

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-group.html#cfn-autoscaling-autoscalinggroup-autoscalinggroupname

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.