Skip to content

Instantly share code, notes, and snippets.

@kthallam
Created January 22, 2020 15:45
Show Gist options
  • Save kthallam/5b293ac431b49622ac83b741518fd346 to your computer and use it in GitHub Desktop.
Save kthallam/5b293ac431b49622ac83b741518fd346 to your computer and use it in GitHub Desktop.
How to update the launch configuration for the existing auto scaling group
#!/bin/bash
# Name of the autosacling group need to replaced with keyworkd in the script
autoscaling_name=`aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[].[AutoScalingGroupName]' --output=text | grep -i <Name of the autosacling group>`
echo $autoscaling_name
launchconfig_name=`aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name $autoscaling_name --output=json | grep -m1 LaunchConfigurationName | cut -d ":" -f 2| sed 's/"//g'`
echo $launchconfig_name
security_group_id=`aws autoscaling describe-launch-configurations --launch-configuration-names $launchconfig_name | grep sg- |awk '{print $1}'| sed 's/"//g'`
echo $security_group_id
amiid=`aws autoscaling describe-launch-configurations --launch-configuration-names $launchconfig_name | grep ami |cut -d ":" -f 2 | sed 's/"//g'| sed 's/,//g'`
echo $amiid
key_name=`aws autoscaling describe-launch-configurations --launch-configuration-names $launchconfig_name | grep KeyName |cut -d ":" -f 2 | sed 's/"//g'| sed 's/,//g'`
echo $key_name
instance_type=`aws autoscaling describe-launch-configurations --launch-configuration-names $launchconfig_name | grep InstanceType |cut -d ":" -f 2 | sed 's/"//g'| sed 's/,//g'`
echo $instance_type
iam_profile=`aws autoscaling describe-launch-configurations --launch-configuration-names test-mongodb-MongodbLcNonEphemeral-107IQP9079D2P | grep -i Iam | cut -d ":" -f 2 | sed 's/"//g'| sed 's/,//g'`
echo $iam_profile
aws autoscaling create-launch-configuration --launch-configuration-name New_Bastion_Config1 --key-name $key_name --image-id $amiid --instance-type $instance_type --security-groups $security_group_id --iam-instance-profile $iam_profile --user-data file://"C:/\/Users/\/tk185114/\/Downloads/\/autoscaling_test.sh"
if [ $? -eq 0 ]
then
echo "New Launchconfig is created"
else
exit 1
fi
aws autoscaling update-auto-scaling-group --auto-scaling-group-name $autoscaling_name --launch-configuration-name New_Bastion_Config1
if [ $? -eq 0 ]
then
echo "Autoscaling group of bastion is updated"
else
echo "AutoScaling Group of bastion is not updated"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment