-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path4-lc-sg-lambda-update-one.py
32 lines (21 loc) · 1.01 KB
/
4-lc-sg-lambda-update-one.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import print_function
import json
import datetime
import time
import boto3
print('Loading function')
def lambda_handler(event, context):
AUTO_SCALLING_GROUP = 'Hayes-Test-ASG'
LC = 'LC-micro'
print("Received event: " + json.dumps(event, indent=2))
# get autoscaling client
client = boto3.client('autoscaling')
# get object for the ASG we're going to update, filter by name of target ASG
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=[AUTO_SCALLING_GROUP])
if not response['AutoScalingGroups']:
return 'No such ASG'
# update ASG to use new LC
client.update_auto_scaling_group(AutoScalingGroupName=AUTO_SCALLING_GROUP, LaunchConfigurationName=LC)
response = client.describe_auto_scaling_groups(AutoScalingGroupNames=[AUTO_SCALLING_GROUP])
newLaunchConfigName = response.get('AutoScalingGroups')[0]['LaunchConfigurationName']
return 'Updated ASG `%s` with new launch configuration `%s`' % (AUTO_SCALLING_GROUP, newLaunchConfigName)