Skip to content

Commit

Permalink
Add cloudwatch events rule for raw sync lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
philerooski committed Sep 19, 2024
1 parent fb220e6 commit 614c478
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config/develop/namespaced/events-rule-raw-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
template:
path: events-rule.yaml
stack_name: "{{ stack_group_config.namespace }}-events-rule-raw-sync"
dependencies:
- develop/namespaced/lambda-raw-sync.yaml
parameters:
RuleName: "{{ stack_group_config.namespace }}-lambda-raw-sync-trigger"
RuleState: DISABLED
LambdaArn: !stack_output_external "{{ stack_group_config.namespace }}-lambda-raw-sync::RawSyncFunctionArn"
CronSchedule: cron(0 0 * * ? *)
stack_tags:
{{ stack_group_config.default_stack_tags }}
12 changes: 12 additions & 0 deletions config/prod/namespaced/events-rule-raw-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
template:
path: events-rule.yaml
stack_name: "{{ stack_group_config.namespace }}-events-rule-raw-sync"
dependencies:
- prod/namespaced/lambda-raw-sync.yaml
parameters:
RuleName: "{{ stack_group_config.namespace }}-lambda-raw-sync-trigger"
RuleState: DISABLED
LambdaArn: !stack_output_external "{{ stack_group_config.namespace }}-lambda-raw-sync::RawSyncFunctionArn"
CronSchedule: cron(0 0 * * ? *)
stack_tags:
{{ stack_group_config.default_stack_tags }}
47 changes: 47 additions & 0 deletions templates/events-rule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: Cloudwatch Events rule to trigger a Lambda on a cron schedule.

Parameters:

RuleName:
Type: String
Description: Name of this rule.

RuleState:
Type: String
Description: >
Whether to enable this rule upon deployment. Suggested values
are "DISABLED" or "ENABLED".
LambdaArn:
Type: String
Description: ARN of the Lambda to trigger.

CronSchedule:
Type: String
Description: When to trigger the Lambda
Default: "cron(0 0 * * ? *)" # At midnight UTC every day

Resources:
MyCloudWatchRule:
Type: AWS::Events::Rule
Properties:
Name: !Ref RuleName
State: !Ref RuleState
ScheduleExpression: !Ref CronSchedule
Targets:
- Arn: !Ref LambdaArn
Id: LambdaTarget

LambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref LambdaArn
Principal: events.amazonaws.com
SourceArn: !GetAtt MyCloudWatchRule.Arn

Outputs:
RuleArn:
Description: "ARN of the Cloudwatch events rule"
Value: !GetAtt MyCloudWatchRule.Arn

0 comments on commit 614c478

Please sign in to comment.