Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
332 lines (331 sloc) 8.56 KB
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"IoTButtonDSN": {
"Type": "String",
"AllowedPattern": "G030[A-Z][A-Z][0=9][0-9][0-9][0-5][0-9][1-7][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X]",
"Description": "The device serial number (DSN) of the AWS IoT Button. This can be found on the back of the button. The DSN must match the pattern of 'G030[A-Z][A-Z][0=9][0-9][0-9][0-5][0-9][1-7][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X][0-9A-HJ-NP-X]'."
},
"CertificateARN": {
"Type": "String",
"Description": "The Amazon Resource Name (ARN) of the existing AWS IoT certificate."
},
"SNSTopicName": {
"Type": "String",
"Default": "aws-iot-button-sns-topic",
"Description": "The name of the Amazon SNS topic for AWS CloudFormation to create."
},
"SNSTopicRoleName": {
"Type": "String",
"Default": "aws-iot-button-sns-topic-role",
"Description": "The name of the IAM role for AWS CloudFormation to create. This IAM role allows AWS IoT to send notifications to the Amazon SNS topic."
},
"GitSha": {
"Type": "String",
"Description": "GitSha to deploy"
},
"LifxAccessToken": {
"Type": "String",
"Description": "A Lifx token to use for authentication"
},
"LifxSingleBulb": {
"Type": "String",
"Description": "Lifx bulb id to trigger on single press"
},
"LifxDoubleBulb": {
"Type": "String",
"Description": "Lifx bulb to trigger on double press"
},
"LifxLongBulb": {
"Type": "String",
"Description": "Lifx bulb id to trigger on long press"
},
"EmailAddress": {
"Type": "String",
"Description": "The email address for the Amazon SNS topic to send information to."
}
},
"Resources": {
"LifxRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"Path": "/lifx/",
"AssumeRolePolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Policies": [
{
"PolicyName": "CloudWatch",
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Action": ["logs:*"],
"Resource": "arn:aws:logs:*:*:*"
}
]
}
}
]
}
},
"LifxFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Join": [
"",
[
"kdecorah-",
{
"Ref": "AWS::Region"
}
]
]
},
"S3Key": {
"Fn::Join": [
"",
[
"lifx/",
{
"Ref": "GitSha"
},
".zip"
]
]
}
},
"Environment": {
"Variables": {
"LifxAccessToken": {
"Ref": "LifxAccessToken"
},
"LifxSingleBulb": {
"Ref": "LifxSingleBulb"
},
"LifxDoubleBulb": {
"Ref": "LifxDoubleBulb"
},
"LifxLongBulb": {
"Ref": "LifxLongBulb"
}
}
},
"Role": {
"Fn::GetAtt": ["LifxRole", "Arn"]
},
"Description": "Turns on/off light in response to SNS messages",
"Handler": "index.handler",
"MemorySize": 128,
"Runtime": "nodejs8.10",
"Timeout": 120
}
},
"LifxFunctionErrorAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmDescription": "Invocation errors",
"MetricName": "Errors",
"Namespace": "AWS/Lambda",
"Statistic": "Sum",
"Period": "60",
"Threshold": "1",
"EvaluationPeriods": "1",
"ComparisonOperator": "GreaterThanThreshold",
"AlarmActions": [
{
"Ref": "SNSTopic"
}
],
"Dimensions": [
{
"Name": "FunctionName",
"Value": {
"Ref": "LifxFunction"
}
}
]
}
},
"IoTThing": {
"Type": "AWS::IoT::Thing",
"Properties": {
"ThingName": {
"Fn::Join": ["", ["iotbutton_", { "Ref": "IoTButtonDSN" }]]
}
}
},
"IoTPolicy": {
"Type": "AWS::IoT::Policy",
"Properties": {
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "iot:Publish",
"Effect": "Allow",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:iot:",
{ "Ref": "AWS::Region" },
":",
{ "Ref": "AWS::AccountId" },
":topic/iotbutton/",
{ "Ref": "IoTButtonDSN" }
]
]
}
}
]
}
}
},
"IoTPolicyPrincipalAttachment": {
"Type": "AWS::IoT::PolicyPrincipalAttachment",
"Properties": {
"PolicyName": {
"Ref": "IoTPolicy"
},
"Principal": {
"Ref": "CertificateARN"
}
}
},
"IoTThingPrincipalAttachment": {
"Type": "AWS::IoT::ThingPrincipalAttachment",
"Properties": {
"Principal": {
"Ref": "CertificateARN"
},
"ThingName": {
"Ref": "IoTThing"
}
}
},
"SNSTopic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"DisplayName": "AWS IoT Button Press Notification",
"Subscription": [
{
"Endpoint": {
"Ref": "EmailAddress"
},
"Protocol": "email"
},
{
"Endpoint": {
"Fn::GetAtt": ["LifxFunction", "Arn"]
},
"Protocol": "lambda"
}
],
"TopicName": {
"Ref": "SNSTopicName"
}
}
},
"SNSTopicRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "iot.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Path": "/",
"Policies": [
{
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": {
"Fn::Join": [
"",
[
"arn:aws:sns:",
{ "Ref": "AWS::Region" },
":",
{ "Ref": "AWS::AccountId" },
":",
{ "Ref": "SNSTopicName" }
]
]
}
}
]
},
"PolicyName": {
"Ref": "SNSTopicRoleName"
}
}
]
}
},
"IoTTopicRule": {
"Type": "AWS::IoT::TopicRule",
"Properties": {
"RuleName": {
"Fn::Join": ["", ["iotbutton_", { "Ref": "IoTButtonDSN" }]]
},
"TopicRulePayload": {
"Actions": [
{
"Sns": {
"RoleArn": {
"Fn::GetAtt": ["SNSTopicRole", "Arn"]
},
"TargetArn": {
"Ref": "SNSTopic"
}
}
}
],
"AwsIotSqlVersion": "2015-10-08",
"RuleDisabled": false,
"Sql": {
"Fn::Join": [
"",
["SELECT * FROM 'iotbutton/", { "Ref": "IoTButtonDSN" }, "'"]
]
}
}
}
},
"SNSPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:invokeFunction",
"FunctionName": {
"Ref": "LifxFunction"
},
"Principal": "sns.amazonaws.com",
"SourceArn": {
"Ref": "SNSTopic"
}
}
}
}
}
You can’t perform that action at this time.