まず、ModuleS3Uploadモジュールを設定する。
「wse-plugin-s3upload.zip」と「aws-java-sdk.zip」をダウンロード解凍して、「Wowzaのインストールフォルダ/lib/」にコピーする。
/usr/local/WowzaStreamingEngine/lib/wse-plugin-s3upload.jar /usr/local/WowzaStreamingEngine/lib/aws-java-sdk-1.11.804.jar |
Name * : ModuleS3Upload
Description * : Uploads recordings to Amazon S3.
Fully Qualified Class Name * : com.wowza.wms.plugin.s3upload.ModuleS3Upload
モジュールを有効にした後、次のプロパティをアプリケーションに追加して、デフォルト設定を調整できる。
AWS S3において、デフォルトではアップロードしたファイルを部外者がそのままURL叩くと、Access Denied になって取得することはできない。
これに対応するためにはBucket Policyを変更する。
{
"Version": "2012-10-17",
"Id": "Policy1592388967983",
"Statement": [
{
"Sid": "Stmt1592388965847",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::vediosync/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"122.210.150.0/24", #home
"61.201.123.123/32" #office
]
}
}
}
]
}
LambdaでS3にアップロードしたファイル名をRDSに自動登録する。
import json import urllib.parse import boto3 import pymysql from pprint import pprint print('Loading function') s3 = boto3.client('s3') #-------------------- #rds settings rds_host = "mydbtest.caeuqamozgcm.ap-northeast-1.rds.amazonaws.com" name = "admin" password = "123456" db_name = "test" try: connection = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5) except pymysql.MySQLError as e: print("ERROR: Unexpected error: Could not connect to MySQL instance. " + e) print("SUCCESS: Connection to RDS MySQL instance succeeded") #-------------------- def lambda_handler(event, context): #print("Received event: " + json.dumps(event, indent=2)) # Get the object from the event and show its content type bucket = event['Records'][0]['s3']['bucket']['name'] print("EVENT:") pprint(event) #bucket = "moviesync-plggd" key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') print("KEY:" + key) #-------------------- # insert mysql try: with connection.cursor() as cursor: # Create a new record sql = "INSERT INTO `tb_files` (`name`, `status`,`uploaded`) VALUES (%s, %s, NOW())" cursor.execute(sql, (key, 1)) # connection is not autocommit by default. So you must commit to save your changes. connection.commit() finally: connection.close() #-------------------- try: response = s3.get_object(Bucket=bucket, Key=key) print("CONTENT TYPE: " + response['ContentType']) return response['ContentType'] except Exception as e: print(e) print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket)) raise e |
【参考】
https://www.wowza.com/docs/how-to-upload-recorded-media-to-an-amazon-s3-bucket-modules3upload