def _create_api_gateway_from_meta(name, meta): """ Create API Gateway with all specified meta. :type name: str :type meta: dict """ required_parameters = ['resources', 'deploy_stage'] validate_params(name, meta, required_parameters) api_resources = meta['resources'] api_id = _API_GATEWAY_CONN.create_rest_api(name)['id'] if api_resources: args = __prepare_api_resources_args(api_id, api_resources) create_pool(_create_resource_from_metadata, args, 1) else: _LOG.info('There is no resources in %s API Gateway description.', name) # add headers # waiter b4 customization time.sleep(10) _LOG.debug('Customizing API Gateway responses...') # _customize_gateway_responses call is commented due to botocore # InternalFailure while performing the call. will be fixed later #_customize_gateway_responses(api_id) # deploy api __deploy_api_gateway(api_id, meta, api_resources) return describe_api_resources(api_id=api_id, meta=meta, name=name)
def _create_api_gateway_from_meta(name, meta): """ Create API Gateway with all specified meta. :type name: str :type meta: dict """ required_parameters = ['resources', 'deploy_stage'] validate_params(name, meta, required_parameters) api_resources = meta['resources'] api_item = _API_GATEWAY_CONN.create_rest_api(name) api_id = api_item['id'] # deploy authorizers authorizers = meta.get('authorizers', {}) for key, val in authorizers.items(): lambda_version = val.get('lambda_version') lambda_name = val.get('lambda_name') lambda_alias = val.get('lambda_alias') lambda_arn = resolve_lambda_arn_by_version_and_alias( lambda_name, lambda_version, lambda_alias) uri = 'arn:aws:apigateway:{0}:lambda:path/2015-03-31/functions/{1}/invocations'.format( CONFIG.region, lambda_arn) _API_GATEWAY_CONN.create_authorizer( api_id=api_id, name=key, type=val['type'], authorizer_uri=uri, identity_source=val.get('identity_source'), ttl=val.get('ttl')) _LAMBDA_CONN.add_invocation_permission( statement_id=api_id, name=lambda_arn, principal='apigateway.amazonaws.com') if api_resources: api_resp = meta.get('api_method_responses') api_integration_resp = meta.get('api_method_integration_responses') args = __prepare_api_resources_args(api_id, api_resources, api_resp, api_integration_resp) create_pool(_create_resource_from_metadata, args, 1) else: _LOG.info('There is no resources in %s API Gateway description.', name) # add headers # waiter b4 customization time.sleep(10) _LOG.debug('Customizing API Gateway responses...') # _customize_gateway_responses call is commented due to botocore # InternalFailure while performing the call. will be fixed later # _customize_gateway_responses(api_id) # deploy api __deploy_api_gateway(api_id, meta, api_resources) return describe_api_resources(api_id=api_id, meta=meta, name=name)
def _create_or_update_api_gateway(name, meta, current_configurations): if current_configurations: # api currently is not located in different regions # process only first object api_output = list(current_configurations.items())[0][1] # find id from the output api_id = api_output['description']['id'] # check that api does not exist api_response = _API_GATEWAY_CONN.get_api(api_id) if api_response: # find all existing resources existing_resources = api_output['description']['resources'] existing_paths = [i['path'] for i in existing_resources] meta_api_resources = meta['resources'] api_resp = meta.get('api_method_responses') api_integration_resp = meta.get('api_method_integration_responses') api_resources = {} for resource_path, resource_meta in meta_api_resources.items(): if resource_path not in existing_paths: api_resources[resource_path] = resource_meta if api_resources: _LOG.debug( 'Going to continue deploy API Gateway {0} ...'.format( api_id)) args = __prepare_api_resources_args( api_id=api_id, api_resources=api_resources, api_resp=api_resp, api_integration_resp=api_integration_resp) create_pool(_create_resource_from_metadata, args, 1) # add headers # waiter b4 customization time.sleep(10) _LOG.debug( 'Customizing API Gateway {0} responses...'.format(api_id)) else: # all resources created, but need to override api_resources = meta_api_resources # _customize_gateway_responses call is commented due to botocore # InternalFailure while performing the call. will be fixed later # _customize_gateway_responses(api_id) # deploy api _LOG.debug('Deploying API Gateway {0} ...'.format(api_id)) __deploy_api_gateway(api_id, meta, api_resources) return describe_api_resources(api_id=api_id, meta=meta, name=name) else: # api does not exist, so create a new return _create_api_gateway_from_meta({'name': name, 'meta': meta}) else: # object is not present, so just create a new api return _create_api_gateway_from_meta({'name': name, 'meta': meta})
def create_sns_topic(args): """ Create sns topic from meta in region/regions. :type args: list """ new_region_args = create_args_for_multi_region(args, ALL_REGIONS) return create_pool(_create_sns_topic_from_meta, new_region_args)
def create_sns_application(args): """ Create sns application from meta in region/regions. :type args: list """ new_region_args = create_args_for_multi_region(args, ALL_REGIONS) return create_pool(_create_platform_application_from_meta, new_region_args)
def create_cloud_watch_rule(args): """ Create CloudWatch rule from meta in region/regions. :type args: list """ new_region_args = create_args_for_multi_region(args, ALL_REGIONS) return create_pool(_create_cloud_watch_rule_from_meta, new_region_args)
def create_s3_bucket(args): return create_pool(_create_s3_bucket_from_meta, args)
def remove_cloud_watch_rules(args): create_pool(_remove_cloud_watch_rule, args)
def remove_cognito_identity_pools(args): create_pool(_remove_cognito_identity_pool, args)
def remove_kinesis_streams(args): create_pool(_remove_kinesis_stream, args)
def api_gateway_update_processor(args): return create_pool(_create_or_update_api_gateway, args, 1)
def create_ebs(args): return create_pool(_create_ebs_app_env_from_meta, args)
def remove_state_machines(args): create_pool(_remove_state_machine, args) if args: time.sleep(60)
def remove_activities(args): create_pool(_remove_activity, args)
def remove_lambda_layers(args): return create_pool(_remove_lambda_layers, args)
def create_lambda_layer(args): return create_pool(create_lambda_layer_from_meta, args)
def remove_lambdas(args): create_pool(_remove_lambda, args)
def update_lambda(args): return create_pool(_update_lambda, args)
def create_lambda(args): """ Create lambdas in pool in sub processes. :type args: list """ return create_pool(_create_lambda_from_meta, args)
def remove_buckets(args): create_pool(_remove_bucket, args)
def remove_ebs_apps(args): create_pool(_remove_ebs_app, args)
def remove_policies(args): create_pool(_remove_policy, args)
def create_api_gateway(args): """ Create api gateway in pool in sub processes. :type args: list """ return create_pool(_create_api_gateway_from_meta, args, 1)
def create_policies(args): return create_pool(_create_policy_from_meta, args)
def create_alarm(args): """ Create alarm in pool in sub processes. :type args: list """ return create_pool(_create_alarm_from_meta, args)
def create_kinesis_stream(args): return create_pool(_create_kinesis_stream_from_meta, args)
def remove_roles(args): create_pool(_remove_role, args)
def remove_alarms(args): create_pool(remove_alarm_list, chunks(args, 100))
def create_roles(args): return create_pool(_create_role_from_meta, args)
def create_cognito_identity_pool(args): """ Create Cognito identity pool in pool in sub processes. :type args: list """ return create_pool(_create_cognito_identity_pool_from_meta, args)