3

I have been using the serverless framework (1.61.0). I have many and many scheduled events that are syncing data from another source. For instance, I am syncing Category entities within one lambda function.

categories:
  handler: functions/scheduled/categories/index.default
  name: ${self:provider.stage}-categories-sync
  description: Sync categories
  events:
    - schedule:
        name: ${self:provider.stage}-moe-categories
        rate: rate(1 hour)
        enabled: true
        input:
          params:
            appId: moe
            mallCode: moe
          scheduled: true

So for this worker, I have another 15 scheduled events. They are preserved as new resources on CloudWatch and which makes it really big. We are exceeding CloudWatch Event limit even if we increased it by submitting a limit increase request to AWS.

Is there any way to define multiple targets for the same CloudWatch Event? So that instead of defining lambda_func_count (15) x event_count (15) x stage_count (dev, staging, prod) resources on CloudWatch, we could just define one event with multiple targets for each individual lambda function.

Currently, it is supported on AWS console but couldn't find a way to achieve this by the serverless framework. enter image description here

saygun
  • 1,438
  • 12
  • 26

2 Answers2

0

One way to help mitigate this issue is to not use the same AWS account for all your stages. Take a look at the AWS Organisations feature that helps you create sub accounts to a master account and if you use Serverless Framework Pro, even on the free tier, you can easily have specific stages deploy to specific AWS accounts. Each sub account has its own set of resources that don't affect other accounts. You could even take this further if you have multiple ways of breaking things across multiple accounts; perhaps you can break it up per Category?

Gareth McCumskey
  • 1,510
  • 7
  • 12
0

Here is an example of a single CloudWatch rule, with multiple targets (each either an AWS Lamdba function, or Lambda alias)

"LCSCombinedKeepWarmRule2":{
    "Type":"AWS::Events::Rule",
    "Properties": {
      "Description":"LCS Keep Functions Warm Rule",
      "ScheduleExpression": "rate(3 minutes)",
      "State":"ENABLED",
      "Targets":[
      {
        "Arn":{"Fn::GetAtt":["CheckCustomer","Arn"]},
        "Id":"CheckCustomerId"
      },
      {
        "Arn":{"Fn::GetAtt":["PatchCustomerId","Arn"]},
        "Id":"PatchCustomerId"
      },
      {
        "Arn":{"Ref":"GetTierAttributes.Alias"},
        "Id":"GetTierAttributes"
      },
      {
        "Arn":{"Ref":"ValidateToken.Alias"},
        "Id":"ValidateTokenId"
      },
      {
        "Arn":{"Ref":"EventStoreRecVoucher.Alias"},
        "Id":"EventStoreRecVoucherId"
      }
      ]
    }
},
JamesMatson
  • 2,522
  • 2
  • 37
  • 86