UNPKG

@incdevco/framework

Version:
264 lines 7.33 kB
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Template For Lambda Function", "Parameters": { "AlarmActionsArn": { "Description": "arn for the alarms to notify when in alarm state", "Type": "String" }, "CodeS3Bucket": { "Type": "String" }, "CodeS3ObjectKey": { "Type": "String" }, "CodeS3ObjectVersion": { "Type": "String" }, "CustomCFResourceFunctionArn": { "Type": "String" }, "DeadLetterQueueArn": { "Default": "", "Description": "leave as empty string for no queue", "Type": "String" }, "Description": { "Type": "String" }, "DurationAlarmPeriod": { "Default": 300, "Type": "Number" }, "DurationAlarmThreshold": { "Default": 150000.0, "Type": "Number" }, "EventLogArn": { "Default": "", "Type": "String" }, "EventLogSubscriptionRoleArn": { "Default": "", "Type": "String" }, "Handler": { "Default": "index.handler", "Type": "String" }, "InsufficientDataActionsArn": { "Default": "", "Description": "arn for the alarms to notify when in insufficient data state", "Type": "String" }, "InvocationAlarmPeriod": { "Default": 300, "Type": "Number" }, "InvocationAlarmThreshold": { "Default": 3.0, "Type": "Number" }, "MemorySize": { "Default": 128, "Type": "Number" }, "OkActionsArn": { "Default": "", "Description": "arn for the alarms to notify when in ok state", "Type": "String" }, "RoleArn": { "Description": "role arn for lambda function", "Type": "String" }, "RoleName": { "Description": "role name for lambda function", "Type": "String" }, "Runtime": { "Default": "nodejs6.10", "Type": "String" }, "Timeout": { "Default": "120", "Type": "String" } }, "Conditions": { "HasDeadLetterQueue": {"Fn::Not": [{"Fn::Equals": ["", {"Ref": "DeadLetterQueueArn"}]}]}, "HasEventLog": {"Fn::Not": [{"Fn::Equals": ["", {"Ref": "EventLogArn"}]}]}, "HasInsufficientDataActions": {"Fn::Not": [{"Fn::Equals": ["", {"Ref": "InsufficientDataActionsArn"}]}]}, "HasOkActions": {"Fn::Not": [{"Fn::Equals": ["", {"Ref": "OkActionsArn"}]}]} }, "Outputs": { "FunctionArn": { "Value": {"Fn::GetAtt": ["Function", "Arn"]} }, "FunctionName": { "Value": {"Ref": "Function"} } }, "Mappings": {}, "Resources": { "DurationAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "ActionsEnabled": true, "AlarmActions": [ {"Ref": "AlarmActionsArn"} ], "AlarmDescription": "Will notify when this lambda function is lasting longer than expected.", "ComparisonOperator": "GreaterThanOrEqualToThreshold", "Dimensions": [ { "Name": "FunctionName", "Value": {"Ref": "Function"} } ], "EvaluationPeriods": 1, "InsufficientDataActions": [ {"Fn::If": [ "HasInsufficientDataActions", {"Ref": "InsufficientDataActionsArn"}, {"Ref": "AWS::NoValue"} ]} ], "MetricName": "Duration", "Namespace": "AWS/Lambda", "OKActions": [ {"Fn::If": [ "HasOkActions", {"Ref": "OkActionsArn"}, {"Ref": "AWS::NoValue"} ]} ], "Period": {"Ref": "DurationAlarmPeriod"}, "Statistic": "Sum", "Threshold": {"Ref": "DurationAlarmThreshold"}, "Unit": "Milliseconds" } }, "Function": { "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": {"Ref": "CodeS3Bucket"}, "S3Key": {"Ref": "CodeS3ObjectKey"}, "S3ObjectVersion": {"Ref": "CodeS3ObjectVersion"} }, "DeadLetterConfig": { "TargetArn": {"Fn::If": [ "HasDeadLetterQueue", {"Ref": "DeadLetterQueueArn"}, {"Ref": "AWS::NoValue"} ]} }, "Description": {"Ref": "Description"}, "Handler": {"Ref": "Handler"}, "MemorySize": {"Ref": "MemorySize"}, "Role": {"Ref": "RoleArn"}, "Runtime": {"Ref": "Runtime"}, "Timeout": {"Ref": "Timeout"} } }, "InvocationAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "ActionsEnabled": true, "AlarmActions": [ {"Ref": "AlarmActionsArn"} ], "AlarmDescription": "Will notify when this lambda function is being invoked more than expected.", "ComparisonOperator": "GreaterThanOrEqualToThreshold", "Dimensions": [ { "Name": "FunctionName", "Value": {"Ref": "Function"} } ], "EvaluationPeriods": 1, "InsufficientDataActions": [ {"Fn::If": [ "HasInsufficientDataActions", {"Ref": "InsufficientDataActionsArn"}, {"Ref": "AWS::NoValue"} ]} ], "MetricName": "Invocations", "Namespace": "AWS/Lambda", "OKActions": [ {"Fn::If": [ "HasOkActions", {"Ref": "OkActionsArn"}, {"Ref": "AWS::NoValue"} ]} ], "Period": {"Ref": "InvocationAlarmPeriod"}, "Statistic": "Sum", "Threshold": {"Ref": "InvocationAlarmThreshold"}, "Unit": "Count" } }, "LogGroup": { "Type": "AWS::Logs::LogGroup", "Properties": { "LogGroupName": {"Fn::Join": ["", [ "/aws/lambda/", {"Ref": "Function"} ]]}, "RetentionInDays": 14 } }, "LogGroupSubscriptionFilter": { "Type": "Custom::CloudWatchSubscriptionFilter", "Condition": "HasEventLog", "Properties": { "ServiceToken": {"Ref": "CustomCFResourceFunctionArn"}, "Options": { "destinationArn": {"Ref": "EventLogArn"}, "filterName": "original event", "filterPattern": "original event", "logGroupName": {"Fn::Join": ["", [ "/aws/lambda/", {"Ref": "Function"} ]]}, "roleArn": {"Ref": "EventLogSubscriptionRoleArn"} } } }, "ManagedPolicy": { "Type": "AWS::IAM::ManagedPolicy", "Properties": { "Description": "policy to allow lambda to write to cloudwatch", "Path": "/", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogStreams" ], "Resource": [ {"Fn::Join": [":", [ "arn:aws:logs", {"Ref": "AWS::Region"}, {"Ref": "AWS::AccountId"}, "log-group", "*" ]]} ] } ] }, "Roles": [ {"Ref": "RoleName"} ] } } } }