Skip to content

Commit

Permalink
make it lambda compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-butcher committed Jul 16, 2024
1 parent e3a9e1c commit 9fcd509
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import json
import boto3
from transferrer.transfer import transfer_shoot
import logging
logging.basicConfig(level=logging.INFO)

logger = logging.getLogger()
logger.setLevel(logging.INFO)

ACCESSION_NUMBER = os.getenv("ACCESSION_NUMBER", "2754")


def lambda_handler(event, context):
shoots = [single_handler(shoot_id) for shoot_id in get_shoot_ids(event)]
return {
'statusCode': 200,
'body': shoots
}


def single_handler(shoot_id):
logger.info(f"transferring {shoot_id}")
transfer_shoot(
from_session=boto3.Session(),
to_session=boto3.Session(),
shoot_number=shoot_id,
accession_number=ACCESSION_NUMBER
)
return shoot_id


def get_shoot_ids(event):
for record in event['Records']:
yield json.loads(record['body'])["Message"]
1 change: 0 additions & 1 deletion src/transferrer/transfer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import tempfile
from transferrer.download import download_shoot
Expand Down
6 changes: 4 additions & 2 deletions src/transferrer/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

logger = logging.getLogger(__name__)

TARGET_BUCKET = os.getenv("TARGET_BUCKET", "wellcomecollection-archivematica-staging-transfer-source")

def upload(session, zipfile_path, target_bucket_name="wellcomecollection-archivematica-staging-transfer-source"):

def upload(session, zipfile_path, target_bucket_name=TARGET_BUCKET):
logger.info(f"uploading {zipfile_path} to {target_bucket_name}")
get_target_bucket(session, target_bucket_name).upload_file(zipfile_path, f"born-digital-accessions/{os.path.basename(zipfile_path)}")

Expand All @@ -18,4 +20,4 @@ def get_target_bucket(session, target_bucket):


if __name__ == "__main__":
upload(boto3.Session(profile_name=os.environ["AWS_TARGET_PROFILE"]).resource('s3'), sys.argv[1])
upload(boto3.Session(profile_name=os.environ["AWS_TARGET_PROFILE"]), sys.argv[1])

0 comments on commit 9fcd509

Please sign in to comment.