0
votes

I am trying to trigger a lambda function, using dynamodb streams on multiple tables using serverless.yml configuration. Is it possible to configure generic arn at triggers of aws serverless.yml.

There are dynamodb tables req_tnt1, req_tnt2, req_tnt2 ...so on. Whenever the req_tnt* table update, I am triggering lambda and storing information in elasticsearch for free text search. I was able todo for single table which trigger lambda and update elastic search, but I am facing issues at enable lambda trigger for all tables(req_tnt*).

1
Is your question if you can attach multiple stream inputs to a lambda function or if you can use wildcards in the stream input configuration?Maurice
i'm looking for wildcard entry for streams arn:aws:dynamodb:region:accountid:table/*/stream/*BALA

1 Answers

0
votes

Unfortunately wildcards aren't possible here.

Defining streams as a Lambda input in Serverless result in CloudFormation that looks like this:

"MyLambdaEventSourceMappingDynamodbOrdersTable": {
      "Type": "AWS::Lambda::EventSourceMapping",
      "DependsOn": "MyLambdaIamRoleLambdaExecution",
      "Properties": {
        "BatchSize": 10,
        "EventSourceArn": {
          "Fn::GetAtt": [
            "OrdersTable",
            "StreamArn"
          ]
        },
        "FunctionName": {
          "Fn::GetAtt": [
            "MyLambdaLambdaFunction",
            "Arn"
          ]
        },
        "StartingPosition": "TRIM_HORIZON",
        "Enabled": "True",
        "MaximumBatchingWindowInSeconds": 60
      }
    },

The resource of type AWS::Lambda::EventSourceMapping uses the property EventSourceArn to specify a single source as per the documentation.

You could add new event source mappings programmatically by writing another Lambda Function that takes a CloudWatch event as its input whenever a new Table is created and then adds an EventSourceMapping for that table to your Lambda Function.

This will probably have scaling limits as the number of event source mappings per Lambda is most likely limited (although I couldn't find the number).