def open_console(app_name, env_name): if utils.is_ssh(): raise NotSupportedError('The console command is not supported' ' in an ssh type session') env = None if env_name is not None: env = elasticbeanstalk.get_environment(app_name=app_name, env_name=env_name) region = aws.get_region_name() if env is not None: page = 'environment/dashboard' else: page = 'application/overview' app_name = utils.url_encode(app_name) console_url = 'console.aws.amazon.com/elasticbeanstalk/home?' console_url += 'region=' + region console_url += '#/' + page + '?applicationName=' + app_name if env is not None: console_url += '&environmentId=' + env.id commonops.open_webpage_in_browser(console_url, ssl=True)
def create_environment(environment): """ Creates an Elastic Beanstalk environment """ LOG.debug('Inside create_environment api wrapper') kwargs = environment.convert_to_kwargs() if environment.database: # need to know region for database string region = aws.get_region_name() # Database is a dictionary kwargs['TemplateSpecification'] = { 'TemplateSnippets': [{ 'SnippetName': 'RdsExtensionEB', 'Order': 10000, 'SourceUrl': 'https://s3.amazonaws.com/' 'elasticbeanstalk-env-resources-' + region + '/eb_snippets/rds/rds.json' }] } result = _make_api_call('create_environment', **kwargs) # convert to object env = Environment.json_to_environment_object(result) request_id = result['ResponseMetadata']['RequestId'] return env, request_id
def create_environment(environment): """ Creates an Elastic Beanstalk environment """ LOG.debug('Inside create_environment api wrapper') kwargs = environment.convert_to_kwargs() if environment.database: # need to know region for database string region = aws.get_region_name() # Database is a dictionary kwargs['TemplateSpecification'] = { 'TemplateSnippets': [ {'SnippetName': 'RdsExtensionEB', 'Order': 10000, 'SourceUrl': 'https://s3.amazonaws.com/' 'elasticbeanstalk-env-resources-' + region + '/eb_snippets/rds/rds.json'} ] } result = _make_api_call('create_environment', **kwargs) # convert to object env = Environment.json_to_environment_object(result) request_id = result['ResponseMetadata']['RequestId'] return env, request_id
def initialize_codecommit(): source_control = SourceControl.get_source_control() try: source_control_setup = source_control.is_setup() except CommandError: source_control_setup = False if not source_control_setup: io.log_error( "Cannot setup CodeCommit because there is no Source Control setup") return if codecommit.region_supported(): codecommit_setup = print_current_codecommit_settings() if codecommit_setup: should_continue = io.get_boolean_response( text='Do you wish to continue?', default=True) if not should_continue: return source_control.setup_codecommit_cred_config() from ebcli.controllers import initialize repository = initialize.get_repository_interactive() branch = initialize.get_branch_interactive(repository) set_repo_default_for_current_environment(repository) set_branch_default_for_current_environment(branch) else: io.log_error("The region {0} is not supported by CodeCommit".format( aws.get_region_name()))
def deploy(app_name, env_name, version, label, message, group_name=None, process_app_versions=False, staged=False, timeout=5, source=None): region_name = aws.get_region_name() build_config = None if fileoperations.build_spec_exists() and version is None: build_config = fileoperations.get_build_configuration() LOG.debug("Retrieved build configuration from buildspec: {0}".format(build_config.__str__())) io.log_info('Deploying code to ' + env_name + " in region " + region_name) if version: app_version_label = version elif source is not None: app_version_label = commonops.create_app_version_from_source( app_name, source, process=process_app_versions, label=label, message=message, build_config=build_config ) io.echo("Starting environment deployment via specified source") process_app_versions = True elif gitops.git_management_enabled() and not staged: app_version_label = commonops.create_codecommit_app_version( app_name, process=process_app_versions, label=label, message=message, build_config=build_config) io.echo("Starting environment deployment via CodeCommit") process_app_versions = True else: app_version_label = commonops.create_app_version( app_name, process=process_app_versions, label=label, message=message, staged=staged, build_config=build_config ) if build_config is not None: buildspecops.stream_build_configuration_app_version_creation( app_name, app_version_label, build_config) elif process_app_versions is True: success = commonops.wait_for_processed_app_versions( app_name, [app_version_label], timeout=timeout or 5 ) if not success: return request_id = elasticbeanstalk.update_env_application_version( env_name, app_version_label, group_name) commonops.wait_for_success_events(request_id, timeout_in_minutes=timeout, can_abort=True, env_name=env_name)
def list_env_names(app_name, verbose, all_apps): region = aws.get_region_name() if verbose: io.echo('Region:', region) if all_apps: for app_name in elasticbeanstalk.get_application_names(): list_env_names_for_app(app_name, verbose) else: list_env_names_for_app(app_name, verbose)
def print_lifecycle_policy(app_name): application = elasticbeanstalk.describe_application(app_name) region = aws.get_region_name() io.echo('Application details for:', app_name) io.echo('{0}Region:'.format(SPACER), region) io.echo('{0}Description:'.format(SPACER), getattr(application, 'Description', NO_ITEM_TOKEN)) io.echo('{0}Date Created:'.format(SPACER), application['DateCreated'].strftime("%Y/%m/%d %H:%M %Z")) io.echo('{0}Date Updated:'.format(SPACER), application['DateUpdated'].strftime("%Y/%m/%d %H:%M %Z")) io.echo('{0}Application Versions:'.format(SPACER), getattr(application, 'Versions', NO_ITEM_TOKEN)) io.echo('{0}Resource Lifecycle Config(s):'.format(SPACER)) resource_configs = application['ResourceLifecycleConfig'] recursive_print_api_dict(resource_configs)
def upload_keypair_if_needed(keyname): keys = [k['KeyName'] for k in ec2.get_key_pairs()] if keyname in keys: return key_material = _get_public_ssh_key(keyname) try: ec2.import_key_pair(keyname, key_material) except AlreadyExistsError: return region = aws.get_region_name() io.log_warning(strings['ssh.uploaded'].replace('{keyname}', keyname) .replace('{region}', region))
def get_quick_link(app_name, env_name): env = elasticbeanstalk.get_environment(app_name=app_name, env_name=env_name) settings = elasticbeanstalk.describe_configuration_settings( app_name, env_name) option_settings = settings['OptionSettings'] environment_type = elasticbeanstalk.get_option_setting( option_settings, 'aws:elasticbeanstalk:environment', 'EnvironmentType') instance_type = elasticbeanstalk.get_option_setting( option_settings, 'aws:autoscaling:launchconfiguration', 'InstanceType') link = 'https://console.aws.amazon.com/elasticbeanstalk/home?' # add region region = aws.get_region_name() link += 'region=' + urllib.parse.quote(region) # add quicklaunch flag link += '#/newApplication' # add application name link += '?applicationName=' + urllib.parse.quote(app_name) # add solution stack link += '&solutionStackName=' + urllib.parse.quote( env.platform.platform_shorthand) # add link += '&tierName=' + env.tier.name if environment_type: link += '&environmentType=' + environment_type if env.version_label: app_version = elasticbeanstalk.get_application_versions( app_name, version_labels=[env.version_label])['ApplicationVersions'][0] source_bundle = app_version['SourceBundle'] source_url = 'https://s3.amazonaws.com/' + source_bundle['S3Bucket'] + \ '/' + source_bundle['S3Key'] link += '&sourceBundleUrl=' + source_url if instance_type: link += '&instanceType=' + instance_type link = _add_database_options(link, option_settings) link = _add_vpc_options(link, option_settings) io.echo(link)
def region_supported(): region = aws.get_region_name() if region is None or region in UNSUPPORTED_REGIONS: return False if region in SUPPORTED_REGIONS: return True # If region support is unknown attempt to make a request and check for # connection error. If there is a connection error it is most likely that # the region is not supported. This is a fall back for regions that have # not been added to our region support lists. try: list_repositories() except EndpointConnectionError as e: LOG.debug('Could not connect to CodeCommit in region {}: {}'.format( region, e)) return False except Exception as e: LOG.debug('Request failed while checking region support: {}'.format(e)) return True