def create_config(session, domain): """Create the CloudFormationConfiguration object. :arg session used to perform lookups :arg domain DNS name of vpc """ config = CloudFormationConfiguration('cloudwatch', domain) names = AWSNames(domain) vpc_id = config.find_vpc(session) lambda_subnets, _ = config.find_all_availability_zones(session, lambda_compatible_only=True) internal_sg = aws.sg_lookup(session, vpc_id, names.internal) loadbalancer_name = names.endpoint_elb if not aws.lb_lookup(session, loadbalancer_name): raise Exception("Invalid load balancer name: " + loadbalancer_name) # TODO Test that MailingListTopic is working. production_mailing_list = const.PRODUCTION_MAILING_LIST mailing_list_arn = aws.sns_topic_lookup(session, production_mailing_list) if mailing_list_arn is None: #config.add_sns_topic("topicList", production_mailing_list) msg = "MailingList {} needs to be created before running config" raise Exception(msg.format(const.PRODUCTION_MAILING_LIST)) config.add_cloudwatch(loadbalancer_name, [mailing_list_arn]) lambda_role = aws.role_arn_lookup(session, 'VaultConsulHealthChecker') config.add_arg(Arg.String( 'VaultConsulHealthChecker', lambda_role, 'IAM role for vault/consul health check.' + domain)) config.add_lambda('VaultLambda', names.vault_monitor, description='Check health of vault instances.', timeout=30, role=Ref('VaultConsulHealthChecker'), security_groups=[internal_sg], subnets=lambda_subnets, handler='index.lambda_handler', file=const.VAULT_LAMBDA) config.add_lambda('ConsulLambda', names.consul_monitor, description='Check health of vault instances.', timeout=30, role=Ref('VaultConsulHealthChecker'), security_groups=[internal_sg], subnets=lambda_subnets, handler='index.lambda_handler', file=const.CONSUL_LAMBDA) # Lambda input data json_str = json.dumps({ 'vpc_id': vpc_id, 'vpc_name': domain, 'topic_arn': mailing_list_arn, }) config.add_cloudwatch_rule('VaultConsulCheck', name=names.vault_consul_check, description='Check health of vault and consul instances.', targets=[ { 'Arn': Arn('VaultLambda'), 'Id': names.vault_monitor, 'Input': json_str }, { 'Arn': Arn('ConsulLambda'), 'Id': names.consul_monitor, 'Input': json_str }, ], schedule='rate(1 minute)', depends_on=['VaultLambda', 'ConsulLambda']) config.add_lambda_permission('VaultPerms', names.vault_monitor, principal='events.amazonaws.com', source=Arn('VaultConsulCheck')) config.add_lambda_permission('ConsulPerms', names.consul_monitor, principal='events.amazonaws.com', source=Arn('VaultConsulCheck')) return config
def create_config(bosslet_config): """Create the CloudFormationConfiguration object. :arg session used to perform lookups :arg domain DNS name of vpc """ config = CloudFormationConfiguration('cloudwatch', bosslet_config) names = bosslet_config.names session = bosslet_config.session domain = bosslet_config.INTERNAL_DOMAIN vpc_id = config.find_vpc() lambda_subnets, _ = config.find_all_subnets(compatibility='lambda') internal_sg = aws.sg_lookup(session, vpc_id, names.internal.sg) loadbalancer_name = names.endpoint_elb.dns if not aws.lb_lookup(session, loadbalancer_name): raise MissingResourceError('ELB', loadbalancer_name) # TODO Test that MailingListTopic is working. production_mailing_list = bosslet_config.ALERT_TOPIC mailing_list_arn = aws.sns_topic_lookup(session, production_mailing_list) if mailing_list_arn is None: raise MissingResourceError('SNS topic', bosslet_config.ALERT_TOPIC) config.add_cloudwatch(loadbalancer_name, [mailing_list_arn]) lambda_role = aws.role_arn_lookup(session, 'VaultConsulHealthChecker') config.add_arg( Arg.String('VaultConsulHealthChecker', lambda_role, 'IAM role for vault/consul health check')) config.add_lambda('VaultLambda', names.vault_monitor.lambda_, description='Check health of vault instances.', timeout=30, role=Ref('VaultConsulHealthChecker'), security_groups=[internal_sg], subnets=lambda_subnets, handler='index.lambda_handler', file=const.VAULT_LAMBDA) # Lambda input data json_str = json.dumps({ 'hostname': names.vault.dns, }) config.add_cloudwatch_rule('VaultCheck', name=names.vault_check.cw, description='Check health of vault instances.', targets=[ { 'Arn': Arn('VaultLambda'), 'Id': names.vault_monitor.lambda_, 'Input': json_str }, ], schedule='rate(2 minutes)', depends_on=['VaultLambda']) config.add_lambda_permission('VaultPerms', names.vault_monitor.lambda_, principal='events.amazonaws.com', source=Arn('VaultCheck')) return config
def create_config(session, domain): """Create the CloudFormationConfiguration object. :arg session used to perform lookups :arg domain DNS name of vpc """ config = CloudFormationConfiguration('cloudwatch', domain) names = AWSNames(domain) vpc_id = config.find_vpc(session) lambda_subnets, _ = config.find_all_availability_zones( session, lambda_compatible_only=True) internal_sg = aws.sg_lookup(session, vpc_id, names.internal) loadbalancer_name = names.endpoint_elb if not aws.lb_lookup(session, loadbalancer_name): raise Exception("Invalid load balancer name: " + loadbalancer_name) # TODO Test that MailingListTopic is working. production_mailing_list = const.PRODUCTION_MAILING_LIST mailing_list_arn = aws.sns_topic_lookup(session, production_mailing_list) if mailing_list_arn is None: #config.add_sns_topic("topicList", production_mailing_list) msg = "MailingList {} needs to be created before running config" raise Exception(msg.format(const.PRODUCTION_MAILING_LIST)) config.add_cloudwatch(loadbalancer_name, [mailing_list_arn]) lambda_role = aws.role_arn_lookup(session, 'VaultConsulHealthChecker') config.add_arg( Arg.String('VaultConsulHealthChecker', lambda_role, 'IAM role for vault/consul health check.' + domain)) config.add_lambda('VaultLambda', names.vault_monitor, description='Check health of vault instances.', timeout=30, role=Ref('VaultConsulHealthChecker'), security_groups=[internal_sg], subnets=lambda_subnets, handler='index.lambda_handler', file=const.VAULT_LAMBDA) config.add_lambda('ConsulLambda', names.consul_monitor, description='Check health of vault instances.', timeout=30, role=Ref('VaultConsulHealthChecker'), security_groups=[internal_sg], subnets=lambda_subnets, handler='index.lambda_handler', file=const.CONSUL_LAMBDA) # Lambda input data json_str = json.dumps({ 'vpc_id': vpc_id, 'vpc_name': domain, 'topic_arn': mailing_list_arn, }) config.add_cloudwatch_rule( 'VaultConsulCheck', name=names.vault_consul_check, description='Check health of vault and consul instances.', targets=[ { 'Arn': Arn('VaultLambda'), 'Id': names.vault_monitor, 'Input': json_str }, { 'Arn': Arn('ConsulLambda'), 'Id': names.consul_monitor, 'Input': json_str }, ], schedule='rate(1 minute)', depends_on=['VaultLambda', 'ConsulLambda']) config.add_lambda_permission('VaultPerms', names.vault_monitor, principal='events.amazonaws.com', source=Arn('VaultConsulCheck')) config.add_lambda_permission('ConsulPerms', names.consul_monitor, principal='events.amazonaws.com', source=Arn('VaultConsulCheck')) return config