【问题标题】:Serverless Framework | How to use wildcard (*) in prefix path无服务器框架 |如何在前缀路径中使用通配符 (*)
【发布时间】:2021-12-10 22:05:38
【问题描述】:

我正在使用无服务器框架来创建 S3 Lambda 触发器:

functions:
  profilePictureInput:
    handler: triggers/handler.profilePictureInput
    memorySize: 10240
    timeout: 25
    events:
      - s3:
          bucket: ${self:custom.mediaInputBucketName}
          existing: true
          event: s3:ObjectCreated:*
          rules:
            - prefix: private/*/profile-pictures

问题:是否可以在前缀路径中使用通配符?

如果对象键是 private/foo/profile-pictures 或 private/bar/profile-pictures,我希望触发 lambda。

上面的例子似乎不起作用(lambda 未触发)

【问题讨论】:

    标签: serverless serverless-framework aws-serverless


    【解决方案1】:

    不,你不能。

    因为通配符星号 (*) 是一个有效字符, 可以在对象键名中使用,Amazon S3 从字面上解释 星号作为前缀或后缀过滤器。您不能使用通配符 表示前缀或后缀的多个字符的字符 对象键名过滤器。

    您必须将所有前缀值字符串注册到 S3 事件。对于你的情况,它看起来像这样:

    functions:
      profilePictureInput:
        handler: triggers/handler.profilePictureInput
        memorySize: 10240
        timeout: 25
        events:
          - s3:
              bucket: ${self:custom.mediaInputBucketName}
              existing: true
              event: s3:ObjectCreated:*
              rules:
                - prefix: private/foo/profile-pictures
                - prefix: private/bar/profile-pictures
    

    【讨论】:

    • “前缀:/profile-pictures”是否也会触发带有键“private/foo/profile-pictures”的对象?
    • @Vingtoft 不,prefix 应该是对象路径的前缀。
    猜你喜欢
    • 2020-04-25
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    • 2019-06-24
    • 2021-09-03
    • 2017-12-29
    • 2022-07-19
    相关资源
    最近更新 更多