Skip to content

Commit 58b23e2

Browse files
committed
Changed to use an EventBridge Rule instead of an EventBridge Schedule.
1 parent bbe5483 commit 58b23e2

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

Monitoring/monitor-ontap-services/cloudformation.yaml

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Metadata:
2121
- implementWatchdogAsLambda
2222
- watchdogRoleArn
2323
- LambdaRoleArn
24-
- SchedulerRoleArn
2524
- createSecretsManagerEndpoint
2625
- createSNSEndpoint
2726
- createCloudWatchLogsEndpoint
@@ -155,11 +154,6 @@ Parameters:
155154
Type: String
156155
Default: ""
157156

158-
SchedulerRoleArn:
159-
Description: "The ARN of the role to use for the Lambda scheduler. This is only needed if you want to provide an existing role, otherwise an appropriate one will be created for you."
160-
Type: String
161-
Default: ""
162-
163157
checkInterval:
164158
Description: "The interval, in minutes, between checks."
165159
Type: Number
@@ -295,7 +289,6 @@ Conditions:
295289
CreateWatchdogRole: !And [!Equals [!Ref watchdogRoleArn, ""], !Equals [!Ref implementWatchdogAsLambda, "true"]]
296290
CreateLambdaRoleWithCW: !And [!Equals [!Ref LambdaRoleArn, ""], !Not [!Equals [!Ref cloudWatchLogGroupArn, ""]]]
297291
CreateLambdaRoleWithoutCW: !And [!Equals [!Ref LambdaRoleArn, ""], !Equals [!Ref cloudWatchLogGroupArn, ""]]
298-
CreateSchedulerRole: !Equals [!Ref SchedulerRoleArn, ""]
299292

300293
Resources:
301294
SecretManagerEndpoint:
@@ -533,42 +526,27 @@ Resources:
533526
- !Sub "arn:aws:s3:::${s3BucketName}/*"
534527
- !Ref cloudWatchLogGroupArn
535528
#
536-
# This is the role that will be assigned to the scheduler EventBridge if the user
537-
# doesn't want to provide a role ARN.
538-
SchedulerRole:
539-
Type: "AWS::IAM::Role"
540-
Condition: CreateSchedulerRole
529+
# Instead of creating a EventBridge schedule, create an EventBridge rule triggered by a schedule.
530+
# This way a separate role doesn't have to be created, just a Lambda permission to allow
531+
# EventBridge to invoke the Lambda function.
532+
LambdaEventRule:
533+
Type: "AWS::Events::Rule"
541534
Properties:
542-
RoleName: !Sub "SchedulerRole-${AWS::StackName}"
543-
AssumeRolePolicyDocument:
544-
Version: "2012-10-17"
545-
Statement:
546-
- Effect: "Allow"
547-
Principal:
548-
Service: "scheduler.amazonaws.com"
549-
Action: "sts:AssumeRole"
550-
551-
Policies:
552-
- PolicyName: "SchedulerPolicy"
553-
PolicyDocument:
554-
Version: "2012-10-17"
555-
Statement:
556-
- Effect: "Allow"
557-
Action:
558-
- "lambda:InvokeFunction"
559-
Resource: !GetAtt LambdaFunction.Arn
535+
Description: "Event rule to trigger the monitor-ontap-services Lambda function."
536+
Name: !Sub "monitor-ontap-services-event-rule-${AWS::StackName}"
537+
ScheduleExpression: !Sub "rate(${checkInterval} minutes)"
538+
State: "ENABLED"
539+
Targets:
540+
- Arn: !GetAtt LambdaFunction.Arn
541+
Id: "MonitorOntapServicesTarget"
560542

561-
LambdaScheduler:
562-
Type: "AWS::Scheduler::Schedule"
543+
LambdaPermissionEventRule:
544+
Type: "AWS::Lambda::Permission"
563545
Properties:
564-
Description: "Schedule the monitor-ontap-services Lambda function."
565-
Name: !Sub "monitor-ontap-services-scheduler-${AWS::StackName}"
566-
FlexibleTimeWindow:
567-
Mode: "OFF"
568-
ScheduleExpression: !Sub "rate(${checkInterval} minutes)"
569-
Target:
570-
Arn: !GetAtt LambdaFunction.Arn
571-
RoleArn: !If [CreateSchedulerRole, !GetAtt SchedulerRole.Arn, !Ref SchedulerRoleArn]
546+
Action: "lambda:InvokeFunction"
547+
FunctionName: !GetAtt LambdaFunction.Arn
548+
Principal: "events.amazonaws.com"
549+
SourceArn: !GetAtt LambdaEventRule.Arn
572550

573551
LambdaLayer:
574552
Type: "AWS::Lambda::LayerVersion"
@@ -629,7 +607,6 @@ Resources:
629607
Code:
630608
ZipFile: |
631609
#!/bin/python3
632-
#
633610
################################################################################
634611
# THIS SOFTWARE IS PROVIDED BY NETAPP "AS IS" AND ANY EXPRESS OR IMPLIED
635612
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -650,7 +627,7 @@ Resources:
650627
# can be run as a standalone program.
651628
#
652629
# Version: v2.19
653-
# Date: 2025-05-26-13:48:43
630+
# Date: 2025-05-27-13:28:30
654631
################################################################################
655632
656633
import json

Monitoring/monitor-ontap-services/monitor_ontap_services.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/python3
2-
#
32
################################################################################
43
# THIS SOFTWARE IS PROVIDED BY NETAPP "AS IS" AND ANY EXPRESS OR IMPLIED
54
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF

0 commit comments

Comments
 (0)