Skip to content

Commit

Permalink
feat: s3 trigger for python
Browse files Browse the repository at this point in the history
  • Loading branch information
wrussell1999 committed Nov 6, 2024
1 parent 5004a26 commit b281606
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions s3-trigger-python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
id: s3-trigger-python
namespace: company.team

variables:
bucket: s3-bucket
region: eu-west-2

tasks:
- id: process_data
type: io.kestra.plugin.scripts.python.Commands
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
containerImage: ghcr.io/kestra-io/kestrapy:latest
namespaceFiles:
enabled: true
inputFiles:
input.csv: "{{ read(trigger.objects[0].uri) }}"
outputFiles:
- data.csv
commands:
- python process_data.py

triggers:
- id: watch
type: io.kestra.plugin.aws.s3.Trigger
interval: "PT1S"
accessKeyId: "{{ secret('AWS_ACCESS_KEY_ID') }}"
secretKeyId: "{{ secret('AWS_SECRET_KEY_ID') }}"
region: "{{ vars.region }}"
bucket: "{{ vars.bucket }}"
filter: FILES
action: MOVE
moveTo:
key: archive/
maxKeys: 1
extend:
title: "Detect New Files in S3 and process them in Python"
description: >-
This flow will be triggered whenever a new file is
detected in the specified S3 bucket. It will download the file into the
internal storage and move the S3 object to an `archive` folder (i.e. S3
object prefix with the name `archive`).
The Python code will read the file as an `inputFile` called `input.csv`
and processing it to generate a new file called `data.csv`.
It's recommended to set the `accessKeyId` and `secretKeyId` properties as
secrets.
This flow assumes AWS credentials stored as secrets `AWS_ACCESS_KEY_ID`,
`AWS_SECRET_ACCESS_KEY`.
tags:
- S3
- Trigger
ee: false
demo: false
meta_description: This flow triggers on new file detection in a specified S3
bucket. It downloads files to internal storage and moves objects to an
'archive' folder. The file is processed by a Python script.

0 comments on commit b281606

Please sign in to comment.