Skip to content

Instantly share code, notes, and snippets.

@ranman
Last active November 11, 2017 16:18
Show Gist options
  • Select an option

  • Save ranman/079258da65b117662f91752a33f85c42 to your computer and use it in GitHub Desktop.

Select an option

Save ranman/079258da65b117662f91752a33f85c42 to your computer and use it in GitHub Desktop.
import boto3
import io
from botocore.vendored import requests
s3 = boto3.resource('s3')
def lambda_handler(event, context):
for record in event['Records']:
buf = io.BytesIO()
s3.Object(
record['s3']['bucket']['name'],
record['s3']['object']['key']
).download_fileobj(buf)
resp = requests.post("WEBHOOK URL GOES HERE", files={'file': buf.getvalue()})
# DO SOMETHING WITH THE RESPONSE
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: A Lambda function to look for missing children in uploads to an S3 bucket
Parameters:
Bucket:
Type: String
Description: "The S3 Bucket you want to enable the lambda for"
Resources:
HitWebHookFunction:
Type: AWS::Serverless::Function
Properties:
Handler: lambda_function.lambda_handler
Policies: AmazonS3ReadOnlyAccess
Runtime: python36
CodeURI: s3://<where_you_keep_your_code>/s3_processor.zip
Events:
PhotoUpload:
Type: S3
Properties:
Bucket: !Sub "arn:aws:s3:::${Bucket}"
Events: s3:ObjectCreated:*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment