This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Amal G Jose' | |
import sys | |
import boto | |
class GetAllInstances(object): | |
def __init__(self): | |
self.aws_access_key = 'XXXXXXXXXXXXXXX' | |
self.aws_secret_key = 'XXXXXXXXXXXXXXX' | |
if self.aws_access_key == '' or self.aws_secret_key == '': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
client = boto3.client("sts", aws_access_key_id="XXXXXXXX", aws_secret_access_key="XXXXXXXX") | |
account_id = client.get_caller_identity()["Account"] | |
print account_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
from urlparse import urlparse | |
__aws_access_key__ = "XXXXXXXXXXXXXXX" | |
__aws_secret_key__ = "XXXXXXXXXXXXX" | |
def s3_client(): | |
""" | |
This method establishes the connection to S3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Amal G Jose' | |
import boto.ec2 | |
class EC2Reboot(object): | |
def __init__(self): | |
self.instance_id_list = ["i-xxxxxx", "i-xxxxxx", "i-xxxxx", "i-xxxx", "i-xxxxx", "i-xxxxx", "i-xxxxx"] | |
self.aws_access_key = "XXXXXXXXXXX" | |
self.aws_secret_key = "XXXXXXXXXXX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import threading | |
def background(f): | |
''' | |
a threading decorator | |
use @background above the function you want to run in the background | |
''' | |
def backgrnd_func(*a, **kw): | |
threading.Thread(target=f, args=a, kwargs=kw).start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%python | |
# Create a temparory dataset | |
data = spark.range(0, 50) | |
data.write.format("delta").save("/tmp/myfirst-delta-table") | |
# Read the data | |
df = spark.read.format("delta").load("/tmp/myfirst-delta-table") | |
df.show() | |
# Updating the dataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from sendgrid import SendGridAPIClient | |
from sendgrid.helpers.mail import Mail | |
message = Mail( | |
from_email=('amal@gmail.com', 'Amal G Jose'), | |
to_emails=[('receiver01@mail.com', 'Receiver 02'), ('receiver02@mail.com', 'Receiver 02')], | |
subject='Sample Email', | |
html_content='My test email') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_first_stack = [] | |
# Push elements to stack using append() | |
my_first_stack.append('edward') | |
my_first_stack.append('sabitha') | |
print('My First Stack') | |
print(my_first_stack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from queue import LifoQueue as lq | |
# Initializing a stack with max size as 2 | |
sample_stack = lq(maxsize=2) | |
# The qsize() function shows the size of the stack | |
print(sample_stack.qsize()) | |
# Now lets push some elements to stack | |
# put() will push elements to stack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque as dq | |
sample_stack = dq() | |
# Push elements to stack using append() function | |
# This is similar to the way we push elements to list | |
sample_stack.append('Sabitha') | |
sample_stack.append('Edward') | |
# Print all the elements in the stack |