Created
November 19, 2022 20:41
-
-
Save jakekara/d59064ea3c90ec0680176517bb8e0a68 to your computer and use it in GitHub Desktop.
use lambda -> s3 as activitypub inbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
from hashlib import md5 | |
from datetime import datetime | |
// simple lambda to act as an activitypub inbox so you can receive | |
// follow requests, comments, etc from other servers. | |
// 1. set this up in a lambda and point API gateway at it. | |
// 2. set the api URL as your inbox in your actor JSON response | |
// assumes you have a bucket called "acitvitypub" and this lambda | |
// has permission to put objects to it | |
def lambda_handler(event, context): | |
event_str = json.dumps(event, indent=2) | |
time_str = datetime.now().strftime("%Y%m%d-%H%M%S") | |
hash_str = md5(event_str.encode()).hexdigest() | |
key = f"events/{time_str}-{hash_str}.json" | |
s3 = boto3.client('s3') | |
response = s3.put_object( | |
Body=json.dumps(event, indent=2), | |
Bucket='activitypub', | |
Key=key | |
) | |
return { | |
'statusCode': 200, | |
'body': json.dumps('message received.') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment