Added aws lambda stuff

This commit is contained in:
frikky
2022-02-11 13:02:38 +01:00
parent c341046f1a
commit 0c599f1e87
3 changed files with 39 additions and 0 deletions
@@ -0,0 +1,2 @@
# AWS Lambda forwarder to Shuffle
This function is made to forward S3 notifications to Shuffle to run a workflow when an object is made or updated.
@@ -0,0 +1,16 @@
#GOOS=linux go build main.go
zip s3_function.zip s3_function.py
WEBHOOK=https://shuffler.io/api/v1/hooks/webhook_eccf47b1-8f6a-49fc-b2b8-383365a22353
ROLE=arn:aws:iam::202262580068:role/service-role/shuffle-forwarder
REGION=us-east-1
BUCKETNAME=helo
aws lambda create-function \
--role $ROLE \
--region $REGION \
--function-name shuffler-webhook-forwarder-3 \
--zip-file fileb://s3_function.zip \
--runtime python3.9 \
--environment Variables={SHUFFLE_WEBHOOK=$WEBHOOK} \
--handler lambda_handler
@@ -0,0 +1,21 @@
import json
import urllib.parse
import urllib3
import os
print('Loading function')
def lambda_handler(event, context):
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
webhook = os.environ.get("SHUFFLE_WEBHOOK")
if not webhook:
return "No webhook environment defined: SHUFFLE_WEBHOOK"
http = urllib3.PoolManager()
ret = http.request('POST', webhook, body=json.dumps(event["Records"][0]).encode("utf-8"))
if ret.status != 200:
return "Bad status code for webhook: %d" % ret.status_code
print("Status code: %d\nData: %s" % (ret.status, ret.data))