# Is used in AWS Lambda to sync stacks when autoscaling group changes.

import base64
import json
import urllib
import urllib2

def lambda_handler(event, context):
  print("Received event: " + json.dumps(event, indent=2))

  host = 'http://CHANGE_ME'
  group_name = event['detail']['AutoScalingGroupName']
  url = '%s/v2.0/provider_notifications/aws/first/autoscaling_groups/%s/changes' % (host, group_name)
  username = 'CHANGE_ME'
  password = 'CHANGE_ME'

  request = urllib2.Request(url, '')
  base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
  request.add_header('Authorization', 'Basic %s' % base64string)
  request.add_header('Content-Type', 'application/json')

  urllib2.urlopen(request)