Skip to content

Instantly share code, notes, and snippets.

@breeko
Created March 18, 2019 10:49
Show Gist options
  • Save breeko/cce4fcb2bad77b75bd51c668d1a5ce6f to your computer and use it in GitHub Desktop.
Save breeko/cce4fcb2bad77b75bd51c668d1a5ce6f to your computer and use it in GitHub Desktop.
Handler function for aws lambda rekognition
import boto3
from utils import download_to_s3, delete_from_s3
s3_bucket = "spypy-images"
client=boto3.client('rekognition')
s3_client=boto3.client('s3')
def detect_images_from_urls(urls):
if type(urls) is str:
urls = [urls]
out = []
for url in urls:
image = download_to_s3(s3_client, s3_bucket, url)
response = client.detect_labels(Image=image, MaxLabels=10)
delete_from_s3(s3_client, s3_bucket, image.get("S3Object").get("Name"))
out.append(response)
return out
def handler(event, context):
urls = event.get("urls") or event["multiValueQueryStringParameters"]["urls"]
out = detect_images_from_urls(urls)
return {
"isBase64Encoded": False,
"statusCode": 200,
"headers": { },
"body": str(out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment