【问题标题】:How to add filter value for s3 trigger event如何为 s3 触发事件添加过滤器值
【发布时间】:2021-05-25 10:38:15
【问题描述】:

我创建了一个带有以下模板的存储桶触发器

我只需要为 test-bucket-3422344 中的文件夹 test/sample/ 触发

    AWSTemplateFormatVersion: "2010-09-09"
    Transform:  'AWS::Serverless-2016-10-31'
    Resources:
    
      MyBucket:
        Type: AWS::S3::Bucket
        Properties:
          BucketName: test-bucket-3422344
    
      rData:
        Type: AWS::Serverless::Function
        Properties:
          CodeUri: functions/load_data     
          FunctionName: sample-function
          Handler: lambda_function.lambda_handler
          Runtime: python3.8
          MemorySize: 3008
          Timeout: 100
          Role: !Sub arn:aws:iam::${AWS::AccountId}:role/main_service_role
          Environment:
            Variables:
              bucket_name: sample-bucket
              file_name: config/test.csv
          Events:
            S3Event:
              Type: S3
              Properties:
                Bucket: !Ref MyBucket
                Events: s3:ObjectCreated:Put   

我添加了类似下面的过滤器与事件并行

       Filter:
            S3Key:
               Rules:
                  - Name: prefix
                  - Value: test/sample

我有错误

E0001 Error transforming template: Resource with id [rData] is invalid. property Filter not defined for resource of type AWS::Serverless::Function```    

【问题讨论】:

    标签: amazon-web-services yaml amazon-cloudformation


    【解决方案1】:

    您的Rules 中不需要-。修正后的模板如下:

    AWSTemplateFormatVersion: "2010-09-09"
    Transform:  'AWS::Serverless-2016-10-31'
    Resources:
    
      MyBucket:
        Type: AWS::S3::Bucket
        Properties:
          BucketName: test-bucket-3422344
          BucketEncryption:
            ServerSideEncryptionConfiguration: 
              - BucketKeyEnabled: true
                ServerSideEncryptionByDefault: 
                  SSEAlgorithm: aws:kms
    
      rData:
        Type: AWS::Serverless::Function
        Properties:
          CodeUri: functions/load_data          
          FunctionName: sample-function
          Handler: lambda_function.lambda_handler
          Runtime: python3.8
          MemorySize: 3008
          Timeout: 100
          Role: !Sub arn:aws:iam::${AWS::AccountId}:role/main_service_role
          Environment:
            Variables:
              bucket_name: sample-bucket
              file_name: config/test.csv
          Events:
            S3Event:
              Type: S3
              Properties:
                Bucket: !Ref MyBucket
                Events: s3:ObjectCreated:Put   
                Filter: 
                  S3Key: 
                    Rules: 
                      - Name: prefix
                        Value: test/sample
    

    【讨论】:

    • 是过滤器:S3Key:规则:-名称:前缀值:测试/样本是函数或存储桶的属性
    • @sim 它的桶。您可以进入 S3 控制台并检查事件详细信息。前缀应该在那里。
    • 我出错了,必须为 MyBucket 启用存储桶日志记录
    • Resources.rMyBucket.Properties.ServerSideEncryptionConfiguration 也必须使用 aws:kws 加密
    • @sim 我更新了答案,但是如果您以后有新的请求/问题,最好为他们提出新的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 2017-12-08
    • 2017-02-19
    • 1970-01-01
    • 2019-01-02
    • 1970-01-01
    相关资源
    最近更新 更多