coding-after-hours / SDSGAS

Simple Discord Study Group Alerting Service
0 stars 0 forks source link

Add CRON to services #3

Open 20jasper opened 1 year ago

20jasper commented 1 year ago

Schedule Lambda to run every Wednesday @ 6:30 PM EST with CRON

We need to add an event rule and a permission to invoke the lambda

SAM example

RefreshPermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: lambda:InvokeFunction
      FunctionName: !Ref YourLambda
      Principal: "events.amazonaws.com"
      SourceArn: !GetAtt YourLambdaEventRule.Arn

 YourLambdaEventRule:
    Type: AWS::Events::Rule
    Properties:
      Description: Scheduled Rule
      Name: String
      # Mins, hours, day-of-month, month, day-of-week, year
      # this example runs every sunday at 12AM utc
      ScheduleExpression: "cron(0 0 ? * SUN *)"
      State: ENABLED
      Targets:
        - Arn: !GetAtt YourLambdaFunction.Arn
          Id: targetFunction1

Warning Lambdas may not run exactly on the time, so we should look into how to tighten the window

Resources:

Brandon-Schefstad commented 1 year ago

Cron Expression:

0 30 18 ? * WED *