Skip to content

Instantly share code, notes, and snippets.

@arfon

arfon/process.py Secret

Last active June 17, 2019 18:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arfon/2d00110b8cd9a4c030d8aba9d09cd9df to your computer and use it in GitHub Desktop.
Save arfon/2d00110b8cd9a4c030d8aba9d09cd9df to your computer and use it in GitHub Desktop.
Example Lambda function
import boto3
import os
import subprocess
import uuid
libdir = os.path.join(os.getcwd(), 'lib')
import warnings
from astropy.utils.data import CacheMissingWarning
warnings.simplefilter('ignore', CacheMissingWarning)
from astropy.io import fits
import numpy as np
from photutils import datasets
from skimage import data
def do_science(event):
file = event['fits_s3_key']
bucket = event['fits_s3_bucket']
root = drz_file.split('/')[-1].split('_')[0]
# Create S3 session
s3 = boto3.resource('s3')
s3_client = boto3.client('s3')
# Download the file from S3 (note this is free from Lambda as long as your
# function is executing in the US-East AWS region) and write out to tmp.
bkt = s3.Bucket(bucket)
bkt.download_file(file, '/tmp/{0}'.format(root),
ExtraArgs={"RequestPayer": "requester"})
# Open the FITS file and print some debug
hdul = fits.open('/tmp/{0}'.format(root))
print(hdul.info())
# Incoming event has the following structure:
# event = {
# 'fits_s3_key': 'S3 key name',
# 'fits_s3_bucket': 'stpubdata',
# 's3_output_bucket': 'output-bucket' # optional
# }
#
# 'process.handler' (this function) is what is called when the Lambda process spawns
def handler(event, context):
print event['s3_output_bucket']
print event['fits_s3_key']
print event['fits_s3_bucket']
do_science(event)
if __name__ == "__main__":
handler('', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment