This file contains hidden or 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 | |
| import logging | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.INFO) | |
| client = boto3.client('sagemaker') | |
| def lambda_handler(event, context): | |
This file contains hidden or 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
| %%writefile lambda.tf | |
| provider "aws" { | |
| region = "eu-west-1" | |
| } | |
| resource "aws_lambda_function" "start_stop_sm" { | |
| function_name = "StopStartSageMakerNotebookInstances" | |
| # The bucket name as created earlier with "aws s3api create-bucket" | |
| s3_bucket = "terraform-serverless-repository" |
This file contains hidden or 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
| %%writefile -a lambda.tf | |
| # IAM role which dictates what other AWS services the Lambda function | |
| # may access. | |
| ## Testing a working example | |
| resource "aws_iam_role" "lambda_exec" { | |
| name = "assume-role" | |
| assume_role_policy = <<EOF | |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ |
This file contains hidden or 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
| %%writefile cloud_watch.tf | |
| ## Based on the location of the instances. This is for Israel where | |
| ## people are working Sunday to Thursday and 5AM GTM is 8AM | |
| resource "aws_cloudwatch_event_rule" "on_duty" { | |
| name = "on_duty" | |
| description = "Fires at the beginning of the working day" | |
| schedule_expression = "cron(0 5 ? * SUN-THU *)" | |
| } | |
| ## people are working Sunday to Thursday and 4PM GTM is 7PM |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| /*train_1217_category training data aggregate by location and category*/ | |
| CREATE TABLE forecast.train_1217_category | |
| WITH ( | |
| format='TEXTFILE', | |
| external_location='s3://forecast-xxxxxx/sagemaker/train_1217_category/', | |
| field_delimiter = ',' | |
| ) AS | |
| SELECT category as item_id, date_format(calendar_date, '%Y-%m-%d') as timestamp, sum(sales) as demand | |
| FROM forecast.compressed_data | |
| where calendar_date < CAST('2018-01-01' AS DATE) |
This file contains hidden or 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
| /*Original Data Compressed*/ | |
| CREATE TABLE forecast.compressed_data | |
| WITH ( | |
| format='PARQUET', | |
| external_location='s3://forecast-xxxxxx/sagemaker/data/', | |
| partitioned_by = ARRAY['year'] | |
| ) AS | |
| SELECT *, year(calendar_date) as year FROM forecast.data; |
This file contains hidden or 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 | |
| session = boto3.Session(region_name='us-east-1') | |
| forecast = session.client(service_name='forecast') | |
| forecastquery = session.client(service_name='forecastquery') | |
| # The name of the dataset that we created with Athena | |
| train_dataset_table = 'train_1217_category' | |
| DATASET_FREQUENCY = "D" | |
| TIMESTAMP_FORMAT = "yyyy-MM-dd" |
This file contains hidden or 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
| predictorName= project+'_ARIMA' | |
| # We will create forecast prediction for two months (60 days) | |
| forecastHorizon = 60 | |
| # Starting the predictor creation job | |
| createPredictorResponse=forecast.create_predictor( | |
| RecipeName=recipe, | |
| DatasetGroupName= datasetGroupName , | |
| PredictorName=predictorName, |
OlderNewer