Skip to content

Instantly share code, notes, and snippets.

@jakekara
Created November 19, 2022 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakekara/d59064ea3c90ec0680176517bb8e0a68 to your computer and use it in GitHub Desktop.
Save jakekara/d59064ea3c90ec0680176517bb8e0a68 to your computer and use it in GitHub Desktop.
use lambda -> s3 as activitypub inbox
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