python
beanstalk
aws
6 years, 4 months ago
#!/usr/bin/python
import boto
import boto.beanstalk, time
import getpass
bean_name = "burstalpha"
### Creating beanstalk instance
def bean_create(bean_name):
conn = boto.beanstalk.connect_to_region('us-west-2')
bean_info = conn.describe_applications(application_names=bean_name)
bean_list_info = bean_info['DescribeApplicationsResponse']['DescribeApplicationsResult']['Applications']
if not bean_list_info:
print "Creating beanstalk application %s" % bean_name
else:
print "%s stalk already exists." % bean_name
return
conn.create_application(bean_name, description=bean_name)
conn.create_application_version(bean_name, 'Sample_Application')
conn.create_environment(bean_name, bean_name, version_label='Sample_Application', solution_stack_name='64bit Windows Server 2012 R2 running IIS 8.5', cname_prefix=bean_name, description=None, option_settings=[('aws:autoscaling:launchconfiguration', 'Ec2KeyName', 'spreedigitalburst'), ('aws:autoscaling:launchconfiguration', 'IamInstanceProfile', 'aws-elasticbeanstalk-ec2-role'),('aws:autoscaling:updatepolicy:rollingupdate', 'RollingUpdateEnabled')], options_to_remove=None, tier_name='WebServer', tier_type='Standard', tier_version='1.0')
time.sleep(10)
dict = conn.describe_events(application_name=bean_name, environment_name=bean_name)
time.sleep(3)
event1 = dict['DescribeEventsResponse']['DescribeEventsResult']['Events'][0]['Message']
event2 = dict['DescribeEventsResponse']['DescribeEventsResult']['Events'][0]['Message']
print event1
while 'Successfully' not in event1:
time.sleep(5)
dict = conn.describe_events(application_name=bean_name, environment_name=bean_name)
if 'Error' in event1:
print event1
print "Encountered error, please wipe out %s application from AWS beanstalk and start over again" % bean_name
exit()
if event1 != event2:
print event2
event1 = dict['DescribeEventsResponse']['DescribeEventsResult']['Events'][0]['Message']
event2 = dict['DescribeEventsResponse']['DescribeEventsResult']['Events'][0]['Message']
time.sleep(240)
if __name__ == "__main__":
bean_create(bean_name)
0 Comments
Please Login to Comment Here