Search code examples
python-3.xamazon-web-servicesamazon-s3aws-lambdapython-zappa

How to add a suffix to an event in lambda function with zappa?


I want to add a suffix (.html for example) to the files that are uploaded to my bucket. I understand how to do it from the amazon console, but I don't understand how to do it from zappa.

Any ideas?

This is more or less my zappa_settings.json

{
    "dev": {
        "app_function": "app.handler",
        "aws_region": "us-east-1",
        "profile_name": "default",
        "project_name": "scrapper",
        "runtime": "python3.8",
        "s3_bucket": "zappabucket",
        "keep_warm":false,
        "apigateway_enabled":false,
        "events": [{
            "function": "app.hanlder",
            "event_source": {
                  "arn":  "arn:aws:s3:::mybucket",
                  "events": [
                    "s3:ObjectCreated:*"
                  ]
               }
        }]
    }
}

Solution

  • This works, but it appears to be undocumented.

     "events": [{
                "function": "app.your_module.your_event_function",
                "event_source": {
                      "arn":  "arn:aws:s3:::mybucket",
                      "events": [
                        "s3:ObjectCreated:*"
                      ],
                      "key_filters": [{
                        "type": "suffix",
                        "value": "yourfile.html"
                      }]
                 }
    }]
    
    

    I just deployed it successfully and made a PR to their docs. They also support prefix.