Skip to content

Instantly share code, notes, and snippets.

@niranjv
niranjv / list_package_contents.r
Last active Aug 8, 2017
List contents of R package
View list_package_contents.r
# Use `ls` to view package contents
# Ref
# - https://stackoverflow.com/questions/12575098/to-see-all-the-content-not-just-objects-in-a-package-in-r
# Example for ISLR package, assuming it is installed
ls(pos="package:ISLR")
# To view only datasets in a package (results will open in a new tab):
data(package="ISLR")
@niranjv
niranjv / deploy_lambda_oracle_rds.sh
Created Jun 17, 2017
Create Python Lambda package to connect to Oracle RDS
View deploy_lambda_oracle_rds.sh
# Create and upload a deployment package for a Python Lambda function
# Assumes EC2 instance is associated with an IAM role with permissions to access S3 & Lambda
# Ref: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
# This script is meant to be used after virtualenv has been setup to connect to Oracle RDS
# see https://gist.github.com/niranjv/2a576a13afe1b323e9e9600ed7de03ef
# Steps:
# - create temp dir
@niranjv
niranjv / setup_lambda_for_oracle_rds.sh
Last active Dec 19, 2019
Setup virtualenv to access Oracle RDS from AWS Lambda
View setup_lambda_for_oracle_rds.sh
# This script allows Python functions in AWS Lambda to query an Oracle RDS instance
# It is meant to run on an EC2 instance running Amazon Linux
# The script has been tested successfully on a t2.micro EC2 instance (Root device type: ebs; Virtualization type: hvm)
# running Amazon Linux AMI 2017.03.0 (HVM), SSD Volume Type - ami-c58c1dd3
# and was developed with the help of AWS Support
# Steps:
# - install Oracle Instant Client
# - create virtualenv
@niranjv
niranjv / install_python_36_amazon_linux.sh
Last active Oct 6, 2021
Install Python 3.6 in Amazon Linux
View install_python_36_amazon_linux.sh
# A virtualenv running Python3.6 on Amazon Linux/EC2 (approximately) simulates the Python 3.6 Docker container used by Lambda
# and can be used for developing/testing Python 3.6 Lambda functions
# This script installs Python 3.6 on an EC2 instance running Amazon Linux and creates a virtualenv running this version of Python
# This is required because Amazon Linux does not come with Python 3.6 pre-installed
# and several packages available in Amazon Linux are not available in the Lambda Python 3.6 runtime
# The script has been tested successfully on a t2.micro EC2 instance (Root device type: ebs; Virtualization type: hvm)
# running Amazon Linux AMI 2017.03.0 (HVM), SSD Volume Type - ami-c58c1dd3
# and was developed with the help of AWS Support
@niranjv
niranjv / change_lambda_logger_format.py
Last active Nov 4, 2021
Change Python logger format in AWS Lambda
View change_lambda_logger_format.py
# Python logger in AWS Lambda has a preset format. To change the format of the logging statement,
# remove the logging handler & add a new handler with the required format
import logging
import sys
def setup_logging():
logger = logging.getLogger()
for h in logger.handlers:
logger.removeHandler(h)