Last active
November 11, 2017 16:18
-
-
Save ranman/079258da65b117662f91752a33f85c42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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