如何为s3触发事件添加过滤器值 [英] How to add filter value for s3 trigger event

查看:73
本文介绍了如何为s3触发事件添加过滤器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用以下模板创建了存储桶触发器

I have created a bucket trigger with following temlate

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

I need to trigger only for the folder test/sample/ which present in test-bucket-3422344

    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   

我在事件旁边添加了如下所示的过滤器

I have added the filter like below parallel to Events

       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```    

推荐答案

您在规则中不需要-.校正后的模板如下:

You have not-needed - in your Rules. The corrected template is as follows:

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

这篇关于如何为s3触发事件添加过滤器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆