Skip to content

Instantly share code, notes, and snippets.

@jpbarto
jpbarto / private-eks-workers.yaml
Created August 18, 2019 06:44
Private EKS Workers CloudFormation with User Data
AWSTemplateFormatVersion: 2010-09-09
Description: Amazon EKS - Node Group
Parameters:
KeyName:
Description: The EC2 Key Pair to allow SSH access to the instances
Type: 'AWS::EC2::KeyPair::KeyName'
NodeImageId:
Description: AMI id for the node instances.
Type: 'AWS::EC2::Image::Id'
NodeInstanceType:
@jpbarto
jpbarto / ide-lifecycle.sh
Last active May 15, 2020 20:03
Lifecycle script for SageMaker notebook startup which installs Theia-IDE
#!/bin/bash
set -e
sudo -u ec2-user -i <<'EOP'
## INSTALL THEIA IDE FROM SOURCE
EC2_HOME=/home/ec2-user
mkdir ${EC2_HOME}/theia && cd ${EC2_HOME}/theia
### begin by installing NVM, NodeJS v10, and Yarn
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
@jpbarto
jpbarto / jpbarto-sagemaker-lifecycle.sh
Last active June 10, 2020 15:40
Default lifecycle configuration for SageMaker notebooks
#!/bin/bash
#
# This script takes about 5 minutes to run and will delay the availability of
# your SageMaker notebook.
# v1.3, release 05may2020
#
# THIS SCRIPT INSTALLS:
# - THEIA IDE w/ Jupyter Server proxy
# - UPGRADES JUPYTERLAB
# - INSTALL VOILA (https://github.com/voila-dashboards/voila)
@jpbarto
jpbarto / aws_iam_role_action_report.sh
Last active June 11, 2020 10:16
Shell script to query AWS CloudTrail and list all actions taken by an AWS Role
#!/bin/bash
###
#
# The following script queries AWS CloudTrail for any events matching $USERNAME which occurred with the permissions
# associated with $ROLE_ARN. All events that have occcurred as of $START_TIME (Unix timestamp in seconds) will
# be retrieved and the IAM actions of those events printed to STDOUT in a sorted and de-duplicated list.
#
# Sample Output:
#
@jpbarto
jpbarto / fashionmnist-mxnet.py
Last active May 8, 2020 19:40
Sample MXNet code for Fashion MNIST
"""
This script is a simple FashionMNIST training script which uses MXNet's.
It has been orchestrated with SageMaker Debugger hook to allow saving tensors during training.
Here, the hook has been created using its constructor to allow running this locally for your experimentation.
When you want to run this script in SageMaker, it is recommended to create the hook from json file.
Please see scripts in either /examples/tensorflow/sagemaker_byoc or /examples/tensorflow/sagemaker_official_container
folder based on your use case.
"""
# Standard Library
import argparse
@jpbarto
jpbarto / workshops-worth-shopping.md
Created May 29, 2020 21:52
Collection of Workshops worth working through
@jpbarto
jpbarto / Deep Dive with Amazon SageMaker.md
Last active August 26, 2020 05:37
Overarching lab guide for an introduction to Amazon SageMaker

Lab 1: Getting started

Create a Jupyter notebook

  1. Visit https://github.com/awslabs/amazon-sagemaker-examples, at the bottom of the page you will find a link to create an Amazon SageMaker notebook
  2. Follow the instructions using an ml.m5.2xlarge instance type.
  3. When the notebook has been created click Open JupyterLab.

Clone the lab materials

Clone the Amazon SageMaker Examples to your notebook from GitHub.

@jpbarto
jpbarto / query_cloudtrail.sh
Created August 20, 2020 04:04
Simple shell script to query AWS CloudTrail for particular actions in an AWS account
#!/bin/bash
# The following shell script uses Amazon Athena to query AWS CloudTrail logs for any occurrences of the
# action sagemaker:ListNotebookInstances. The query returns the user identity who invoked the API, along
# with the region where the API was called. A simple count of the number of invokes is outputted as a
# result.
SQL="SELECT useridentity.arn, eventname, eventsource, awsregion, sourceipaddress, errorcode, eventtime FROM cloudtrail_logs_account_logging WHERE eventsource = 'sagemaker.amazonaws.com' AND eventname in ('ListNotebookInstances') AND eventtime > '2020-04-15' LIMIT 3;"
EXEC_ID=$(aws athena start-query-execution --query-string "$SQL" --result-configuration OutputLocation=s3://my-s3-logging-bucket/queries --query 'QueryExecutionId' --output text)
@jpbarto
jpbarto / stop_run_instance.json
Created August 20, 2020 09:40
Example of how to use IAM Policy Simulator to test IAM policy effects on permissions (also works for SCPs)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Deny",
"Action": "ec2:RunInstances",
"Resource": "*"
}
]
@jpbarto
jpbarto / restore-database-with-pitr.sh
Created October 30, 2020 10:10
Bash Shell Script to restore and time the restoration of an RDS database using Point in Time Recovery (PITR)
#!/bin/bash
set -e
AWS_REGION=eu-west-2
SOURCE_DATABASE_NAME=database-1
RESTORE_TIME='2020-10-28T22:02:01+00:00'
NEW_DATABASE_NAME="rds-db-$RANDOM"