Skip to content

Instantly share code, notes, and snippets.

View sofianhamiti's full-sized avatar

Sofian Hamiti sofianhamiti

View GitHub Profile
@sofianhamiti
sofianhamiti / on_start.sh
Last active June 4, 2021 14:31
lifecycle configuration to install Theia
set -e
sudo -u ec2-user -i <<'EOP'
#####################################
## INSTALL THEIA IDE
#####################################
cd ${HOME}
git clone https://github.com/SofianHamiti/amazon-sagemaker-notebook-instance-lifecycle-config-theia.git lifecycle-config
library(randomForest)
library(MASS)
set.seed(42)
# Prepare dataset
cutoff = sample(1:nrow(Boston), nrow(Boston) * 0.7) # 70/30 split between test and train
train_set <- Boston[cutoff,]
test_set <- Boston[-cutoff,]
library(randomForest)
library(jsonlite)
# download model file from S3 into /tmp folder
system("aws s3 cp ${S3_MODEL_URI} /tmp/model.rds")
handler <- function(body, ...) {
data <- fromJSON(txt = body)
# load model
model <- readRDS("/tmp/model.rds")
FROM public.ecr.aws/lambda/provided
ENV R_VERSION=4.0.3
ENV PATH="${PATH}:/opt/R/${R_VERSION}/bin/"
# install R
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& yum -y install https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm \
openssl-devel \
libxml2-devel \
@sofianhamiti
sofianhamiti / app.py
Last active February 12, 2021 21:41
from aws_cdk import (
aws_lambda,
aws_iam,
aws_apigatewayv2,
core
)
class InferenceStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
{
"crim": 0.0063,
"zn": 18,
"indus": 2.31,
"chas": 0,
"nox": 0.538,
"rm": 6.575,
"age": 65.2,
"dis": 4.09,
"rad": 1,
import json
import boto3
import logging
from botocore.config import Config
logger = logging.getLogger()
logger.setLevel(logging.INFO)
config = Config(retries = {'max_attempts': 10,'mode': 'standard'})
sagemaker = boto3.client('sagemaker', config=config)
AWSTemplateFormatVersion: 2010-09-09
Description: Deploys a scheduled Lambda function to shutdown Studio kernels automatically
Resources:
#================================================================================
# LAMBDA
#================================================================================
StudioShutdownFunction:
Type: AWS::Lambda::Function
Properties:
{
"CRIM": 0.0063,
"ZN": 18,
"INDUS": 2.31,
"CHAS": 0,
"NOX": 0.538,
"RM": 6.575,
"AGE": 65.2,
"DIS": 4.09,
"RAD": 1,
from aws_cdk import core
from stacks.api_stack import ApiStack
from stacks.lambda_stack import LambdaStack
from stacks.state_machine_stack import StateMachineStack
class InferenceStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)