Skip to content

Instantly share code, notes, and snippets.

View chloegrace94's full-sized avatar

Chloe Grace Young chloegrace94

View GitHub Profile
@chloegrace94
chloegrace94 / COCO_Image_Viewer.ipynb
Created August 25, 2021 10:38 — forked from akTwelve/COCO_Image_Viewer.ipynb
COCO Image Viewer | immersivelimit.com/tutorials/create-coco-annotations-from-scratch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chloegrace94
chloegrace94 / post_to_slack_response_url.py
Created October 2, 2018 15:53
Post to Slack using response URL
# Post to Slack
def post_to_slack(channel_id, message_ts, original_message, message_response, response_url):
try:
slack_data = {
"channel":channel_id,
"ts":message_ts,
"text":original_message,
#"attachment_type": "default",
"attachments": [
@chloegrace94
chloegrace94 / RDS_EC2_stop.py
Created October 2, 2018 15:51
Functions to stop and start RDS and EC2 instances
# Stop RDS instances
def stop_start_rds(session, inst_name, action, instance_id_or_arn):
try:
client = session.client('rds', region_name=region)
db_instances = client.describe_db_instances(DBInstanceIdentifier=inst_name)
# get the instance if it can be found
if len(db_instances) != 0:
db_instance = db_instances['DBInstances'][0]
@chloegrace94
chloegrace94 / tag_reserve_instance.py
Created October 2, 2018 15:48
Tag EC2 and RDS instances to reserve them
# Instance tagging function
def instance_tagger(action_value, resource_type, instance_id_or_arn, instance_name, user_id):
# Slack users
# cyoung = @cyoung
# user_2 = @user_2
owner_dict = {
"cyoung" : "xxxxxxxxx",
"user_2" : "zzzzzzzzz"
@chloegrace94
chloegrace94 / interactive_slack_message_formatting.py
Created October 2, 2018 15:43
Interactive Slack message formatting used by reminder Lambda for running instance reminder service
{
"text": message,
"channel": slack_owner,
"attachments": [
{
"fallback": "Sorry, an error has occured",
"callback_id": "instance_reminder",
"attachment_type": "default",
"actions": [
{
@chloegrace94
chloegrace94 / integration_request_mapping_template.vtl
Created October 2, 2018 15:32
API Gateway integration request mapping template for interactive Slack reminder service
{
"method": "$context.httpMethod",
"body" : $input.json('$'),
"headers": {
#foreach($param in $input.params().header.keySet())
"$param": "$util.escapeJavaScript($input.params().header.get($param))"
#if($foreach.hasNext),#end
#end
}
}
@chloegrace94
chloegrace94 / invoke_lambda.py
Created October 2, 2018 15:27
Invoke a Lambda function using boto3
import boto3
client = boto3.client('lambda')
# Invoke Lambda using invocation type: 'Event'
response = client.invoke(
FunctionName='final_response_lambda',
InvocationType='Event',
LogType='None',
Payload= json.dumps(body),
@chloegrace94
chloegrace94 / instance_stop_message_update.py
Created October 2, 2018 15:25
Stop instance - Slack message with status update attachment
elif action_type == "button" and action_value == "stop":
message_response = ":bomb: Stopping *" + str(instance_name) + "*..."
message_update = {
"channel":channel_id,
"ts":message_ts,
"text":original_message,
#"attachment_type": "default",
"attachments": [
{
@chloegrace94
chloegrace94 / instance_reserve_message_update.py
Created October 2, 2018 15:23
Reserve instance - Slack message with status update attachment
elif action_type == "select":
if action_value == '1':
message_response = ":money_with_wings: Reserving *" + str(instance_name) + "* for *" + action_value + "* day..."
else:
message_response = ":money_with_wings: Reserving *" + str(instance_name) + "* for *" + action_value + "* days..."
message_update = {
"channel":channel_id,
"ts":message_ts,
"text":original_message,
@chloegrace94
chloegrace94 / instance_keep_up_menu.py
Created October 2, 2018 15:18
Keep instance up - Slack message with menu attachment
if action_type == "button" and action_value == "keep_up":
message_update = {
"channel":channel_id,
"ts":message_ts,
"text":original_message,
"attachments": [
{
"fallback": ":money_with_wings: Instance *" + str(instance_name) + "* staying up!",
"callback_id": "instance_reminder",