Last active
February 13, 2019 18:32
-
-
Save manavskohli/7157b9d973197c5096efba799cc42732 to your computer and use it in GitHub Desktop.
This file contains 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
# Original source code: | |
# aws.amazon.com/blogs/compute/content-replication-using-aws-lambda-and-amazon-s3/ | |
import urllib | |
import boto3 | |
import ast | |
import json | |
print('Loading function') | |
def lambda_handler(event, context): | |
s3 = boto3.client('s3') | |
sns_message = ast.literal_eval(event['Records'][0]['Sns']['Message']) | |
target_bucket = 'target-bucket-two' | |
source_bucket = str(sns_message['Records'][0]['s3']['bucket']['name']) | |
key = str(urllib.unquote_plus(sns_message['Records'][0]['s3']['object']['key']) | |
.decode('utf8')) | |
copy_source = {'Bucket':source_bucket, 'Key':key} | |
# TODO: any other processing here | |
s3.copy_object(Bucket=target_bucket, Key=key, CopySource=copy_source) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment