当对象 dateAttribute 等于 X 时,通过 DynamoDB Streams 触发 lambda

问题描述 投票:0回答:1

堆栈:

  • 无服务器,版本:

    Framework Core: 2.71.0 (local)
    Plugin: 5.5.4
    SDK: 4.3.2
    Components: 3.18.2
    
  • PHP 7.2

具有特定条件的 DynamoDB 流应触发 lambda,我的无服务器函数可以正常工作:

  createStatementFiles:
    handler: lambda/statement.php
    timeout: 899 # 14min 59s
    layers:
      - arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
    role: CreateStatementFilesRole
    reservedConcurrency: 10
    events:
      - stream:
          type: dynamodb
          arn: arn:aws:dynamodb:eu-west-3:<account_id>:table/<table_name>/stream/<stream_id>
          filterPatterns:
            - eventName: [INSERT]
              dynamodb:
                NewImage:
                  __partitionKey:
                    S: [statementBalance]

我绝对想要的是 DynamoDB 流触发 lambda 当且仅当 statementsBalance 的日期 = statementsBalance 月份的最后一天,例如:

$currentDate = '2022-10-25';
$statementBalance->getDate() = '2022-02-10';
$lastDayOfTheMonth = '2022-02-28', not equal last day of the month of $currentDate (2022-10-31)

这是我想要的图表:

如果您有其他解决方案可以满足我的需求,可以防止每次插入statementBalance时触发lambda,我很感兴趣。

提前非常感谢您的帮助,

amazon-web-services amazon-dynamodb serverless amazon-dynamodb-streams
1个回答
1
投票

我为

StatementBalance
对象添加了一个新属性; “
(bool) lastDayOfMonth

此属性将触发 Lambda 当且仅当

lastDayOfMonth = true

  createStatementFiles:
    handler: lambda/statement.php
    timeout: 899 # 14min 59s
    layers:
      - arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
    role: CreateStatementFilesRole
    reservedConcurrency: 10
    events:
      - stream:
          type: dynamodb
          arn: ${fetchStreamARN:${opt:stage}-${opt:client}-Project}
          filterPatterns:
            - eventName: [INSERT]
              dynamodb:
                NewImage:
                  __partitionKey:
                    S: [statementBalance]
                  lastDayOfMonth:
                    N: [1]

感谢@jarmod!

© www.soinside.com 2019 - 2024. All rights reserved.