Skip to content

Instantly share code, notes, and snippets.

View davidrosenstark's full-sized avatar

David Rosenstark davidrosenstark

View GitHub Profile
@davidrosenstark
davidrosenstark / SSMEncryptedPropertyPlaceholderConfigurer.java
Last active August 14, 2018 09:58
PropertyPlaceholderConfigurer for reading from AWS Parameter Store
import com.amazonaws.auth.AWSCredentialsProvider;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import java.util.Map;
import java.util.Properties;
/**
* Class for reading properties from AWS Parameter Store and allowing spring to inject them in the
@davidrosenstark
davidrosenstark / SSMClient.java
Last active August 31, 2020 05:54
Java client to wrap access to AWS parameter store
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient;
import com.amazonaws.services.simplesystemsmanagement.model.*;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
---
AWSTemplateFormatVersion: '2010-09-09'
Description: "Monitoring - Dashboard - Http Errors"
Parameters:
EnvironmentName:
Type: String
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import java.util.HashMap;
import java.util.Map;
--configurations '[{"Classification":"hive-site","Properties":{"hive.metastore.client.factory.class":"com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory"}},{"Classification":"spark-hive-site","Properties":{"hive.metastore.client.factory.class":"com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory"}}]'
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("SimpleApp").enableHiveSupport().getOrCreate()
spark.sql("use dev")
spark.sql("show tables").show()
spark.sql("SELECT * FROM myTable").show(10)
from flask import jsonify
from flask_restx import Resource, Namespace
health_api = Namespace('health', 'health check api')
@health_api.route('health_check', doc=False)
class HealthCheck(Resource):
def get(self):
response = {"Status": "OK"}
return jsonify(response)
@davidrosenstark
davidrosenstark / flask_injector.py
Created May 7, 2020 13:14
flask_injector_setup
from injector import inject
from flask import request, g
@inject
def api_before_request(db_connection: MyDbConnectionClass):
if not request.path.startswith("/health_check"):
logger.info(f"Request received to: {request.url}, headers: {request.headers}, body: {request.json}”)
g.user_info = db_connection.query_user_info(request.headers.get('Username’))
@davidrosenstark
davidrosenstark / __init__.py
Last active May 11, 2020 07:22
flask init
from flask_restx import Api
from .health_check.health import health_api as health_namespace
api = Api(
title='Title',
version='1.0',
description='description',
doc='/api-docs',
)
import logging
import os
from flask import Flask,
from flask_injector import FlaskInjector
from injector import singleton, Injector, Module
from common_dal import DataAccessLayer, initialize_db_connection
from apis.api_queries import api_before_request