Skip to content

Instantly share code, notes, and snippets.

@niranjv
niranjv / change_lambda_logger_format.py
Last active February 7, 2024 11:03
Change Python logger format in AWS Lambda
# 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)
@niranjv
niranjv / install_python_36_amazon_linux.sh
Last active January 30, 2023 21:49
Install Python 3.6 in Amazon Linux
# 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 / setup_lambda_for_oracle_rds.sh
Last active December 19, 2019 19:39
Setup virtualenv to access Oracle RDS from AWS Lambda
# 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 / deploy_lambda_oracle_rds.sh
Created June 17, 2017 17:15
Create Python Lambda package to connect to Oracle RDS
# 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 / list_package_contents.r
Last active August 8, 2017 20:00
List contents of R package
# 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")