{ "AWSTemplateFormatVersion": "2010-09-09", "Metadata": { "Comment1": "COPYRIGHT NOTICE + LICENSE: Copyright 2017 University of Alaska Fairbanks\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nThe Software is provided \"as is,\" without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.", "AWS::CloudFormation::Designer": { "9c7a7dbf-1817-4700-aca9-c7c721b7e007": { "size": { "width": 60, "height": 60 }, "position": { "x": 60, "y": 90 }, "z": 1, "embeds": [] }, "ce865440-9388-46d4-b025-94fab10d8e3a": { "size": { "width": 60, "height": 60 }, "position": { "x": 180, "y": 90 }, "z": 1, "embeds": [] }, "d0811f8c-4661-4d86-9cdf-696ca23ab8a1": { "size": { "width": 60, "height": 60 }, "position": { "x": 60, "y": 210 }, "z": 1, "embeds": [], "isassociatedwith": [ "ce865440-9388-46d4-b025-94fab10d8e3a" ] }, "bd39c401-f2b8-4419-85c2-8fd5e2d04c6b": { "size": { "width": 60, "height": 60 }, "position": { "x": 180, "y": 210 }, "z": 1, "embeds": [] }, "ddd35859-0dc9-4a8d-ac85-ed890347b726": { "size": { "width": 60, "height": 60 }, "position": { "x": 300, "y": 90 }, "z": 1, "embeds": [], "isassociatedwith": [ "bd39c401-f2b8-4419-85c2-8fd5e2d04c6b" ] }, "3917ac56-0288-4ffe-bdd8-cf747eb6c95e": { "size": { "width": 60, "height": 60 }, "position": { "x": 300, "y": 210 }, "z": 1, "embeds": [] }, "6359a6fd-8be9-41e0-8b25-bb97e9a82bd6": { "size": { "width": 60, "height": 60 }, "position": { "x": 60, "y": 330 }, "z": 1, "embeds": [] }, "6b9dc2a7-f74f-4a2f-92b9-26116791c4fe": { "size": { "width": 60, "height": 60 }, "position": { "x": 180, "y": 330 }, "z": 1, "embeds": [], "isassociatedwith": [ "9c7a7dbf-1817-4700-aca9-c7c721b7e007" ] }, "152613cd-bf17-42f9-bfc3-a999e4ec8967": { "size": { "width": 60, "height": 60 }, "position": { "x": 300, "y": 330 }, "z": 1, "embeds": [], "isassociatedwith": [ "6b9dc2a7-f74f-4a2f-92b9-26116791c4fe" ] }, "470f4d5f-ff70-456c-bd14-6d3152e75136": { "size": { "width": 60, "height": 60 }, "position": { "x": 420, "y": 90 }, "z": 1, "embeds": [], "isassociatedwith": [ "152613cd-bf17-42f9-bfc3-a999e4ec8967" ] }, "8c20ee56-b964-488b-921a-859273784315": { "size": { "width": 60, "height": 60 }, "position": { "x": 420, "y": 210 }, "z": 1, "embeds": [], "isrelatedto": [ "470f4d5f-ff70-456c-bd14-6d3152e75136" ] }, "a9d82206-0a9c-4013-965a-1262313fe60a": { "size": { "width": 60, "height": 60 }, "position": { "x": 420, "y": 330 }, "z": 1, "embeds": [], "isassociatedwith": [ "152613cd-bf17-42f9-bfc3-a999e4ec8967" ] }, "d86b71b7-1670-4be6-a638-5a4572ef7bfa": { "size": { "width": 60, "height": 60 }, "position": { "x": 60, "y": 450 }, "z": 1, "embeds": [], "isrelatedto": [ "a9d82206-0a9c-4013-965a-1262313fe60a" ] } } }, "Parameters": { "KeyName": { "Description": "Name of an existing EC2 KeyPair to enable SSH access to instances", "Type": "AWS::EC2::KeyPair::KeyName" }, "AMI": { "Description": "Name of an Amazon Machine Image to apply to the EC2 instances, i.e. ami-ff922c80 for Sentinel-1 RTC", "Default": "ami-ff922c80", "Type": "String" }, "Subnets": { "Description": "Name of an existing Subnet(s) to use for EC2 instances", "Type": "List" }, "SecurityGroup": { "Description": "Name of an existing Security groupfile to be applied to instances", "Type": "AWS::EC2::SecurityGroup::GroupName" }, "SNSTopicUser": { "Default": "email@domain.com", "NoEcho": false, "Description": "A valid email address to subscribe to the SNS Topics", "Type": "String", "MinLength": 7, "MaxLength": 26 } }, "Resources": { "asgS1RTCASG": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c" ], "Cooldown": "300", "DesiredCapacity": "0", "HealthCheckGracePeriod": "300", "HealthCheckType": "EC2", "MaxSize": "5", "MinSize": "0", "NotificationConfigurations": [ { "TopicARN": { "Ref": "topicS1RTCScaleEvent" }, "NotificationTypes": [ "autoscaling:EC2_INSTANCE_LAUNCH", "autoscaling:EC2_INSTANCE_LAUNCH_ERROR", "autoscaling:EC2_INSTANCE_TERMINATE", "autoscaling:EC2_INSTANCE_TERMINATE_ERROR" ] } ], "LaunchConfigurationName": { "Ref": "lcS1RTClaunchcfg" }, "Tags": [ { "Key": "Name", "Value": { "Fn::Join": [ "", [ { "Ref": "AWS::StackName" }, "_S1_RTC_worker" ] ] }, "PropagateAtLaunch": true }, { "Key": "Project", "Value": "S1_RTC_pipeline", "PropagateAtLaunch": true }, { "Key": "Output-bucket", "Value": { "Ref": "s3s1rtcoutput" }, "PropagateAtLaunch": true }, { "Key": "queue_name", "Value": { "Fn::GetAtt": [ "queueS1RTCqueue", "QueueName" ] }, "PropagateAtLaunch": true }, { "Key": "Input-bucket", "Value": { "Ref": "s3s1rtcinput" }, "PropagateAtLaunch": true } ], "TerminationPolicies": [ "Default" ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "152613cd-bf17-42f9-bfc3-a999e4ec8967" } } }, "iamS1RTCrole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "ec2.amazonaws.com" ] }, "Action": [ "sts:AssumeRole" ] } ] }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/AmazonEC2FullAccess", "arn:aws:iam::aws:policy/AmazonS3FullAccess", "arn:aws:iam::aws:policy/AmazonSQSFullAccess", "arn:aws:iam::aws:policy/AmazonSNSFullAccess", "arn:aws:iam::aws:policy/AmazonSESFullAccess", "arn:aws:iam::aws:policy/CloudWatchFullAccess" ] } }, "iamS1RTCprofile": { "Type": "AWS::IAM::InstanceProfile", "Properties": { "Path": "/", "Roles": [ { "Ref": "iamS1RTCrole" } ] } }, "lcS1RTClaunchcfg": { "Type": "AWS::AutoScaling::LaunchConfiguration", "Properties": { "ImageId": { "Ref": "AMI" }, "InstanceType": "m5.4xlarge", "KeyName": { "Ref": "KeyName" }, "IamInstanceProfile": { "Ref": "iamS1RTCprofile" }, "SpotPrice": "0.38", "SecurityGroups": [ { "Ref": "SecurityGroup" } ], "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "VolumeSize": 200 } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "6b9dc2a7-f74f-4a2f-92b9-26116791c4fe" } } }, "queueS1RTCqueue": { "Type": "AWS::SQS::Queue", "Properties": { "DelaySeconds": "0", "MaximumMessageSize": "262144", "MessageRetentionPeriod": "345600", "ReceiveMessageWaitTimeSeconds": "0", "VisibilityTimeout": "30" }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "bd39c401-f2b8-4419-85c2-8fd5e2d04c6b" } } }, "topicS1RTCScaleEvent": { "Type": "AWS::SNS::Topic", "Properties": { "DisplayName": "S1_RTC_Scale_Event", "Subscription": [ { "Endpoint": { "Ref": "SNSTopicUser" }, "Protocol": "email" } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "ce865440-9388-46d4-b025-94fab10d8e3a" } } }, "sqspolicyS1RTCqueue": { "Type": "AWS::SQS::QueuePolicy", "Properties": { "Queues": [ { "Ref": "queueS1RTCqueue" } ], "PolicyDocument": { "Version": "2012-10-17", "Id": { "Ref": "AWS::AccountId" }, "Statement": [ { "Sid": "Sid1512504667471", "Effect": "Allow", "Principal": { "AWS": { "Ref": "AWS::AccountId" } }, "Action": "SQS:*", "Resource": { "Fn::GetAtt": [ "queueS1RTCqueue", "Arn" ] } }, { "Sid": "Sid1512504721320", "Effect": "Allow", "Principal": "*", "Action": "SQS:*", "Resource": { "Fn::GetAtt": [ "queueS1RTCqueue", "Arn" ] } } ] } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "ddd35859-0dc9-4a8d-ac85-ed890347b726" } } }, "snspolicyS1RTCScalein": { "Type": "AWS::SNS::TopicPolicy", "Properties": { "Topics": [ { "Ref": "topicS1RTCScaleEvent" } ], "PolicyDocument": { "Version": "2008-10-17", "Id": "__default_policy_ID", "Statement": [ { "Sid": "__default_statement_ID", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": [ "SNS:GetTopicAttributes", "SNS:SetTopicAttributes", "SNS:AddPermission", "SNS:RemovePermission", "SNS:DeleteTopic", "SNS:Subscribe", "SNS:ListSubscriptionsByTopic", "SNS:Publish", "SNS:Receive" ], "Resource": { "Ref": "topicS1RTCScaleEvent" }, "Condition": { "StringEquals": { "AWS:SourceOwner": { "Ref": "AWS::AccountId" } } } } ] } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "d0811f8c-4661-4d86-9cdf-696ca23ab8a1" } } }, "scalingS1RTCScaleOut": { "Type": "AWS::AutoScaling::ScalingPolicy", "Properties": { "AdjustmentType": "ChangeInCapacity", "PolicyType": "SimpleScaling", "ScalingAdjustment": 1, "AutoScalingGroupName": { "Ref": "asgS1RTCASG" } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "a9d82206-0a9c-4013-965a-1262313fe60a" } } }, "scalingS1RTCScaleIn": { "Type": "AWS::AutoScaling::ScalingPolicy", "Properties": { "AdjustmentType": "ChangeInCapacity", "PolicyType": "SimpleScaling", "ScalingAdjustment": -1, "AutoScalingGroupName": { "Ref": "asgS1RTCASG" } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "470f4d5f-ff70-456c-bd14-6d3152e75136" } } }, "alarmS1RTCScaleout": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "ActionsEnabled": "true", "AlarmDescription": "Alarm to trigger ASG to create nodes to handle work in queue", "ComparisonOperator": "GreaterThanThreshold", "EvaluationPeriods": "1", "MetricName": "ApproximateNumberOfMessagesVisible", "Namespace": "AWS/SQS", "Period": "300", "Statistic": "Average", "Threshold": "0.0", "AlarmActions": [ { "Ref": "scalingS1RTCScaleOut" }, { "Ref": "topicS1RTCScaleEvent" } ], "Dimensions": [ { "Name": "QueueName", "Value": { "Fn::GetAtt": [ "queueS1RTCqueue", "QueueName" ] } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "d86b71b7-1670-4be6-a638-5a4572ef7bfa" } } }, "alarmS1RTCScalein": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "ActionsEnabled": "true", "AlarmDescription": "Alarm to trigger ASG to remove nodes from cluster", "ComparisonOperator": "LessThanOrEqualToThreshold", "EvaluationPeriods": "2", "MetricName": "CPUUtilization", "Namespace": "AWS/EC2", "Period": "300", "Statistic": "Average", "Threshold": "5", "AlarmActions": [ { "Ref": "topicS1RTCScaleEvent" }, { "Ref": "scalingS1RTCScaleIn" } ], "Dimensions": [ { "Name": "AutoScalingGroupName", "Value": { "Ref": "asgS1RTCASG" } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "8c20ee56-b964-488b-921a-859273784315" } } }, "s3s1rtcinput": { "Type": "AWS::S3::Bucket", "Properties": { "AccessControl": "Private", "VersioningConfiguration": { "Status": "Suspended" }, "NotificationConfiguration": { "QueueConfigurations": [ { "Event": "s3:ObjectCreated:*", "Filter": { "S3Key": { "Rules": [ { "Name": "suffix", "Value": ".zip" } ] } }, "Queue": { "Fn::GetAtt": [ "queueS1RTCqueue", "Arn" ] } } ] } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "6359a6fd-8be9-41e0-8b25-bb97e9a82bd6" } } }, "s3s1rtcoutput": { "Type": "AWS::S3::Bucket", "Properties": { "AccessControl": "Private", "VersioningConfiguration": { "Status": "Suspended" } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "3917ac56-0288-4ffe-bdd8-cf747eb6c95e" } } }, "PipelineMasterEc2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "InstanceInitiatedShutdownBehavior": "stop", "ImageId": "ami-a514adda", "InstanceType": "t2.micro", "KeyName": { "Ref": "KeyName" }, "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ "#!/bin/bash -xe\n", "/etc/run_at_startup.sh\n" ]]}}, "IamInstanceProfile": { "Ref": "iamS1RTCprofile" }, "SecurityGroups": [ { "Ref": "SecurityGroup" } ], "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "VolumeSize": 200 } } ], "Tags": [ { "Key" : "Name", "Value": { "Fn::Join": [ "", [ { "Ref": "AWS::StackName" }, "_S1_RTC_Master" ] ] } }, { "Key": "Project", "Value": "S1_RTC_pipeline" }, { "Key": "Input-bucket", "Value": { "Ref": "s3s1rtcinput" } }, { "Key": "queue_name", "Value": { "Fn::GetAtt": [ "queueS1RTCqueue", "QueueName" ] } } ] } } }, "Description": "S1_RTC_Template" }