Closed yuyangwu0325 closed 3 years ago
When using AWS PowerShell Tool to get the information about the Auto Scaling group. However, this is not working for them and the Launch Template is shown as null.
I replicate this issue and found this is caused by Auto Scaling group has Mix Instance Type option enabled. Based on my test, if Auto Scaling group does not override the instance type provided by the ASG, the tool will work as expected:
PS C:\Users\Administrator> (Get-ASAutoScalingGroup -AutoScalingGroupName TestASG).LaunchTemplate
LaunchTemplateId LaunchTemplateName Version
lt-08b7c95168857c3c8 BestLT $Latest
However, as long as you enable this option, the command will fail:
PS C:\Users\Administrator> (Get-ASAutoScalingGroup -AutoScalingGroupName TestASG).LaunchTemplate PS C:\Users\Administrator>
This is caused by Launch Template info is return under MixedInstancesPolicy property when MIG is used in Auto Scaling group. Therefore, using the following command can return the correct info: (Get-ASAutoScalingGroup -AutoScalingGroupName test-autoscaling-group).MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification
This can be quite confusing. Hence we would like to suggest you to update the public doc: https://docs.aws.amazon.com/powershell/latest/reference/items/Get-ASAutoScalingGroup.html
Based on my review of the code for PowerShell CmdLet Get-ASAutoscalingGroup
, it is just invoking the DescribeAutoScalingGroups
on the service.
I observed the following using AWS CLI command aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name test-autoscaling-group
:
Combine purchase options and instance types
option, CLI gave the following output:{
"AutoScalingGroups": [
{
"AutoScalingGroupName": "test-autoscaling-group",
"AutoScalingGroupARN": "arn:aws:autoscaling:us-east-2:139480602983:autoScalingGroup:08474ae9-dc8c-4ad4-829b-d7d9a6edaead:autoScalingGroupName/test-autoscaling-group",
"LaunchTemplate": {
"LaunchTemplateId": "lt-06095fd619cb40371",
"LaunchTemplateName": "test-launch-template",
"Version": "$Default"
},
"MinSize": 1,
"MaxSize": 1,
"DesiredCapacity": 1,
"DefaultCooldown": 300,
"AvailabilityZones": [
"us-east-2b"
],
"LoadBalancerNames": [],
"TargetGroupARNs": [],
"HealthCheckType": "EC2",
"HealthCheckGracePeriod": 300,
"Instances": [
{
"InstanceId": "i-0653cb2eaef0102b8",
"InstanceType": "t2.micro",
"AvailabilityZone": "us-east-2b",
"LifecycleState": "InService",
"HealthStatus": "Healthy",
"LaunchTemplate": {
"LaunchTemplateId": "lt-06095fd619cb40371",
"LaunchTemplateName": "test-launch-template",
"Version": "1"
},
"ProtectedFromScaleIn": false
}
],
"CreatedTime": "2021-03-29T21:19:22.108000+00:00",
"SuspendedProcesses": [],
"VPCZoneIdentifier": "subnet-0e554b79afc8e48ed",
"EnabledMetrics": [],
"Tags": [],
"TerminationPolicies": [
"Default"
],
"NewInstancesProtectedFromScaleIn": false,
"ServiceLinkedRoleARN": "arn:aws:iam::139480602983:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling"
}
]
}
Notice the LaunchTemplate
property at the ASG object level.
Combine purchase options and instance types
option, CLI gave the following output:
{
"AutoScalingGroups": [
{
"AutoScalingGroupName": "test-autoscaling-group",
"AutoScalingGroupARN": "arn:aws:autoscaling:us-east-2:139480602983:autoScalingGroup:08474ae9-dc8c-4ad4-829b-d7d9a6edaead:autoScalingGroupName/test-autoscaling-group",
"MixedInstancesPolicy": {
"LaunchTemplate": {
"LaunchTemplateSpecification": {
"LaunchTemplateId": "lt-06095fd619cb40371",
"LaunchTemplateName": "test-launch-template",
"Version": "$Default"
},
"Overrides": [
{
"InstanceType": "t2.micro"
},
{
"InstanceType": "t2.small"
}
]
},
"InstancesDistribution": {
"OnDemandAllocationStrategy": "prioritized",
"OnDemandBaseCapacity": 0,
"OnDemandPercentageAboveBaseCapacity": 70,
"SpotAllocationStrategy": "capacity-optimized"
}
},
"MinSize": 1,
"MaxSize": 1,
"DesiredCapacity": 1,
"DefaultCooldown": 300,
"AvailabilityZones": [
"us-east-2b"
],
"LoadBalancerNames": [],
"TargetGroupARNs": [],
"HealthCheckType": "EC2",
"HealthCheckGracePeriod": 300,
"Instances": [
{
"InstanceId": "i-0653cb2eaef0102b8",
"InstanceType": "t2.micro",
"AvailabilityZone": "us-east-2b",
"LifecycleState": "InService",
"HealthStatus": "Healthy",
"LaunchTemplate": {
"LaunchTemplateId": "lt-06095fd619cb40371",
"LaunchTemplateName": "test-launch-template",
"Version": "1"
},
"ProtectedFromScaleIn": false
}
],
"CreatedTime": "2021-03-29T21:19:22.108000+00:00",
"SuspendedProcesses": [],
"VPCZoneIdentifier": "subnet-0e554b79afc8e48ed",
"EnabledMetrics": [],
"Tags": [],
"TerminationPolicies": [
"Default"
],
"NewInstancesProtectedFromScaleIn": false,
"ServiceLinkedRoleARN": "arn:aws:iam::139480602983:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling",
"CapacityRebalance": true
}
]
}
Notice now that there is no LaunchTemplate
property it ASG object level. Instead it returned MixedInstancesPolicy
property at ASG object level, which has LaunchTemplate
child property.
On the similar lines, if you now examine the value of (Get-ASAutoScalingGroup -AutoScalingGroupName test-autoscaling-group).MixedInstancesPolicy
, it returns the following:
InstancesDistribution LaunchTemplate
--------------------- --------------
Amazon.AutoScaling.Model.InstancesDistribution Amazon.AutoScaling.Model.LaunchTemplate
So the value of (Get-ASAutoScalingGroup -AutoScalingGroupName test-autoscaling-group).LaunchTemplate
is correctly returned as null
based on observation from AWS CLI output and this is not a bug.
To get the value of LaunchTemplate, use the following command (Get-ASAutoScalingGroup -AutoScalingGroupName test-autoscaling-group).MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification
.
Refer https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/AutoScaling/Generated/Model/AutoScalingGroup.cs. There are separate LaunchTemplate
and MixedInstancesPolicy
properties.
MixInstancesPolicy
class is here https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/AutoScaling/Generated/Model/MixedInstancesPolicy.cs
Hence the PowerShell CmdLet's behavior is correct.
I think documentation update is the best way going forward.
We can add an example showing differences between mix instance type and normal scneario.
Example added
This is a :question: general question document