Added a S3 -> Webhook forwarder
This commit is contained in:
@@ -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,26 @@
|
|||||||
|
import json
|
||||||
|
import urllib.parse
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
|
||||||
|
#print('Loading function')
|
||||||
|
|
||||||
|
def lambda_handler(event, context):
|
||||||
|
#print("Received event: " + json.dumps(event, indent=2))
|
||||||
|
|
||||||
|
# Get the object from the event and show its content type
|
||||||
|
bucket = event['Records'][0]['s3']['bucket']['name']
|
||||||
|
|
||||||
|
print(type(event))
|
||||||
|
print("Getting bucket: %s" % bucket)
|
||||||
|
webhook = os.environ.get("SHUFFLE_WEBHOOK")
|
||||||
|
if not webhook:
|
||||||
|
return "No webhook environment defined: SHUFFLE_WEBHOOK"
|
||||||
|
|
||||||
|
ret = requests.post(webhook, json=event["Records"][0])
|
||||||
|
if ret.status_code != 200:
|
||||||
|
return "Bad status code for webhook: %d" % ret.status_code
|
||||||
|
|
||||||
|
print("Status code: %d\nData: %s" % (ret.status_code, ret.text))
|
||||||
|
|
||||||
|
# response = s3.get_object(Bucket=bucket, Key=key)
|
||||||
Reference in New Issue
Block a user