From 0c599f1e87979511b0cbcfb5a595d73afa6c39b1 Mon Sep 17 00:00:00 2001 From: frikky Date: Fri, 11 Feb 2022 13:02:38 +0100 Subject: [PATCH] Added aws lambda stuff --- functions/extensions/aws-s3-lambda/README.md | 2 ++ .../extensions/aws-s3-lambda/s3_deploy.sh | 16 ++++++++++++++ .../extensions/aws-s3-lambda/s3_function.py | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 functions/extensions/aws-s3-lambda/README.md create mode 100644 functions/extensions/aws-s3-lambda/s3_deploy.sh create mode 100644 functions/extensions/aws-s3-lambda/s3_function.py diff --git a/functions/extensions/aws-s3-lambda/README.md b/functions/extensions/aws-s3-lambda/README.md new file mode 100644 index 00000000..f665851a --- /dev/null +++ b/functions/extensions/aws-s3-lambda/README.md @@ -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. diff --git a/functions/extensions/aws-s3-lambda/s3_deploy.sh b/functions/extensions/aws-s3-lambda/s3_deploy.sh new file mode 100644 index 00000000..cedda90f --- /dev/null +++ b/functions/extensions/aws-s3-lambda/s3_deploy.sh @@ -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 diff --git a/functions/extensions/aws-s3-lambda/s3_function.py b/functions/extensions/aws-s3-lambda/s3_function.py new file mode 100644 index 00000000..82838a4e --- /dev/null +++ b/functions/extensions/aws-s3-lambda/s3_function.py @@ -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))