Create a new SNS topic with name: [ENV]-wowzer-iphone-fanout
Go to Other topic actions > Edit topic policy > Advanced View and replace the contents of the default policy with the following:
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:eu-west-1:956149323110:[ENV]-wowzer-iphone-fanout",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:s3:::[ENV]-wowzer-iphone"
}
}
}
]
}
Create a new Event CopyNewFiles
selecting only the following options: Post, Put and Multipart Upload.
Select the SNS topic with name [ENV]-wowzer-iphone-fanout
and save.
Enter the following function name: [ENV]-wowza-repository
Select Python 2.7 as Runtime and enter the following code:
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 = context.function_name
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}
print "Copying %s from bucket %s to bucket %s ..." % (key, source_bucket, target_bucket)
s3.copy_object(Bucket=target_bucket, Key=key, CopySource=copy_source)
Leave the default handler and create a custom role with name lambda_basic_execution_[ENV]_wowza_repository
and the following IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::[ENV]-wowzer-iphone/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::[ENV]-wowza-repository/*"
]
}
]
}
Change the function's timeout to 5 minutes.
From the SNS console, create a new subscription for the topic [ENV]-wowzer-iphone-fanout
and the Lambda function [ENV]-wowza-repository
.
Upload a file in [ENV]-wowzer-iphone
and make sure it gets properly copied to [ENV]-wowza-repository
.
Create a new SNS topic with name: [ENV]-wowza-repository-fanout
Go to Other topic actions > Edit topic policy > Advanced View and replace the contents of the default policy with the following:
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:eu-west-1:956149323110:[ENV]-wowza-repository-fanout",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:s3:::[ENV]-wowza-repository"
}
}
}
]
}
Create a new Event CopyNewFiles
selecting only the following options: Post, Put and Multipart Upload.
Select the SNS topic with name [ENV]-wowza-repository-fanout
and save.
Enter the following function name: [ENV]-wowzer-iphone
Select Python 2.7 as Runtime and enter the following code:
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 = context.function_name
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}
print "Copying %s from bucket %s to bucket %s ..." % (key, source_bucket, target_bucket)
s3.copy_object(Bucket=target_bucket, Key=key, CopySource=copy_source)
Leave the default handler and create a custom role with name lambda_basic_execution_[ENV]_wowzer_iphone
and the following IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::[ENV]-wowza-repository/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::[ENV]-wowzer-iphone/*"
]
}
]
}
Change the function's timeout to 5 minutes.
From the SNS console, create a new subscription for the topic [ENV]-wowza-repository-fanout
and the Lambda function [ENV]-wowzer-iphone
.
Upload a file in [ENV]-wowzer-iphone
and make sure it gets properly copied to [ENV]-wowza-repository
.
Upload a file in [ENV]-wowza-repository
and make sure it gets properly copied to [ENV]-wowzer-iphone
.
Use AWS S3 console to copy all existing files in [ENV]-wowzer-iphone
to [ENV]-wowza-repository
.