Skip to content

Instantly share code, notes, and snippets.

@mikeapted
mikeapted / as-sqs-depth.config
Created September 26, 2018 18:25
Autoscale Elastic Beanstalk worker tier based on SQS queue depth
Resources:
ScaleUpPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AdjustmentType: ChangeInCapacity
AutoScalingGroupName:
Ref: AWSEBAutoScalingGroup
Cooldown: '1'
ScalingAdjustment: '1'
ScaleDownPolicy:
import json
import datetime
import random
import boto3
kinesis = boto3.client('kinesis', region_name='us-east-1') #<--- change region if not in N.Virginia
def getData(sensorType, sensorName, lowVal, highVal):
data = {}
data['sensorType'] = sensorType
CREATE OR REPLACE STREAM "TEMP_STREAM" (
"sensorName" varchar (40),
"sensorValue" integer,
"ANOMALY_SCORE" DOUBLE);
-- Creates an output stream and defines a schema
CREATE OR REPLACE STREAM "DESTINATION_SQL_STREAM" (
"sensorName" varchar(40),
"sensorValue" integer,
"ANOMALY_SCORE" DOUBLE,
"created" TimeStamp);
select sensorname, sensorvalue, anomalyscore from analytic_csv2parquet where anomalyscore > 2 limit 10
select sensorname, sensorvalue, anomalyscore from YourInitial_bigdata.analytic_csv2parquet where anomalyscore > 2 limit 10;
create external schema YourInitial_bigdata from data catalog
database 'YourInitial_bigdata'
iam_role 'Role ARN Copied in Step 12'
region 'us-east-1';
select sensorname, sensorvalue, anomalyscore from YourInitial_bigdata.analytic_csv2parquet where anomalyscore > 2 limit 10;
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])
import boto3
import json
def lambda_handler(event, context):
payload = '1,13000 \n 1,20000 \n 2,3500 \n 2,5000 \n 3,3000 \n 3,3300 \n 4,2 \n 4,10'
endpoint_name = 'YourInitials-kmeans-anomalydetection'
runtime = boto3.client('runtime.sagemaker')
response = runtime.invoke_endpoint(EndpointName=endpoint_name,