UNPKG

@incdevco/framework

Version:
180 lines 5.2 kB
AWSTemplateFormatVersion: '2010-09-09' Description: 'lambda function' Parameters: AlarmActionsArn: Description: 'arn for the alarms to notify when in alarm state' Type: 'String' CodeS3Bucket: Description: 'bucket where code package is stored' Type: 'String' CodeS3ObjectKey: Description: 'key for code package in bucket' Type: 'String' CodeS3ObjectVersion: Description: 'version of the code package to use' Type: 'String' DeadLetterQueueArn: Description: 'arn of the queue to use for dead letter queue' Type: 'String' Description: Default: '' Description: 'this will be the functions description' Type: 'String' DurationAlarmPeriod: Default: 300 Description: 'Period for the duration alarm' Type: 'Number' DurationAlarmThreshold: Default: 150000.0 Description: 'Threshold in milliseconds for the duration alarm' Type: 'Number' EventLogArn: Default: '' Description: 'arn for the event log log subscription' Type: 'String' EventLogSubscriptionRoleArn: Default: '' Description: 'role arn for the log subscription' Type: 'String' Handler: Default: 'index.handler' Description: 'lambda function handler name' Type: 'String' InsufficientDataActionsArn: Default: '' Description: 'arn for insufficient data actions' Type: 'String' InvocationAlarmPeriod: Default: 300 Description: 'period in seconds for invocation alarm' Type: 'Number' InvocationAlarmThreshold: Default: 3.0 Description: 'Threshold for invocation alarm' Type: 'Number' MemorySize: Default: 128 Type: 'Number' OkActionsArn: Default: '', Description: 'arn for okay actions' Type: 'String' RoleArn: Description: 'role arn for lambda function' Type: 'String' Runtime: Default: 'nodejs6.10' Description: 'function run time' Type: 'String' Timeout: Default: '120' Description: 'timeout for lambda function in seconds' Type: 'String' Outputs: FunctionArn: Value: !GetAtt: Function.Arn FunctionName: Value: !Ref: Function Conditions: HasDeadLetterQueue: !Not: [!Equals: ['', !Ref DeadLetterQueueArn]] HasEventLog: !Not: [!Equals: ['', !Ref EventLogArn]] HasInsufficientDataActions: !Not: [!Equals: ['', !Ref InsufficientDataActionsArn]] HasOkActions: !Not: [!Equals: ['', !Ref OkActionsArn]] 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: - !If ['HasInsufficientDataActions', !Ref InsufficientDataActionsArn, !Ref 'AWS::NoValue'] MetricName: 'Duration' Namespace: 'AWS/Lambda' OkActions: - !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: !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: - !If ['HasInsufficientDataActions', !Ref InsufficientDataActionsArn, !Ref 'AWS::NoValue'] MetricName: 'Invocation' Namespace: 'AWS/Lambda' OkActions: - !If ['HasOkActions', !Ref OkActionsArn, !Ref 'AWS::NoValue'] Period: !Ref DurationAlarmPeriod Statistic: 'Sum' Threshold: !Ref DurationAlarmThreshold Unit: 'Count' LogGroup: Type: 'AWS::Logs::LogGroup' Properties: LogGroupName: !Join ['', ['/aws/lambda/', !Ref Function]] RetentionInDays: 14 EventLogSubscriptionFilter: Type: 'AWS::Logs::SubscriptionFilter' Properties: DestinationArn: !Ref EventLogArn FilterPattern: 'original event' LogGroupName: !Join ['', ['/aws/lambda/', !Ref Function]] RoleArn: !Ref EventLogSubscriptionRoleArn