Learn how to use the AWS SDK for Java to retrieve content from an Amazon S3 Media Cache source. Media Cache is a caching mechanism included with Wowza Streaming Engine™ media server software that increases the scalability of video-on-demand (VOD) streaming.
Note: The AWS SDK for Java is available in Wowza Streaming Engine 4.8.8.01 and later.
About Amazon S3 Media Cache sources
Wowza Streaming Engine provides built-in functionality for retrieving content from Amazon S3. As an alternative, you can also use the AWS SDK for Java. The SDK provides methods for authenticating to Amazon S3 that don't require you to directly provide your AWS access key ID and secret key to Wowza Streaming Engine.
Enable the SDK
- Navigate to [install-dir]/conf/ and open MediaCache.xml in a text editor.
- Add the useAWSSDK property to the <MediaCacheSources>/<MediaCacheSource>/<Properties> container element (be sure to get the correct <MediaCacheSource> container element).
<Property> <Name>useAWSSDK</Name> <Value>true</Value> <Type>Boolean</Type> </Property>
- Restart Wowza Streaming Engine to apply the changes.
Configure AWS authentication
To retrieve content from a non-public Amazon S3 bucket, you must provide AWS credentials to the SDK. Wowza Streaming Engine supports the following credential retrieval methods:
Note: For more information, see Supplying and Retrieving AWS Credentials in the AWS SDK for Java version 2 Developer Guide.
- Environment variables – Uses the EnvironmentVariableCredentialsProvider class from the SDK to retrieves credentials from environment variables. To use this method, you must configure the following key-value pairs as environment variables:
AWS_PROFILE=default AWS_ACCESS_KEY_ID=[access key ID] AWS_SECRET_ACCESS_KEY=[secret key]
- Named profile – Retrieves credentials from a credentials profile created using the AWS CLI. To specify the profile name, add the awsProfileName property to the <MediaCacheSources>
/<MediaCacheSource>/<Properties> container element.
<Property> <Name>awsProfileName</Name> <Value>[profile name]</Value> <Type>String</Type> </Property>
In certain cases, you may also need to specify the path to the credentials file. This is most commonly required on Windows and Linux machines when the .aws/ folder is in a location that doesn't match the User account where the service is running. To specify the path, add the awsProfilesCredentialsFilePath property to the <MediaCacheSources>/<MediaCacheSource>/<Properties> container element.
<Property> <Name>awsProfilesCredentialsFilePath</Name> <Value>C:\Users\user123\.aws\credentials</Value> <Type>String</Type> </Property>
- Static credentials – Provides AWS credentials directly to Wowza Streaming Engine. Credentials can be configured when adding an Amazon S3 source in Wowza Streaming Engine Manager, or by adding them to the <MediaCacheSources>/<MediaCacheSource>/<Properties> container element in MediaCache.xml.
Note: Wowza Streaming Engine will default to using this method if the access key ID and secret key are specified for the source. To switch to another credential retrieval method, you must remove these values from the <MediaCacheSources>/<MediaCacheSource>/<Properties> container element in MediaCache.xml.
To configure your access key ID and secret key in MediaCache.xml, add the awsAccessKeyId and awsSecretAccessKey properties to the <MediaCacheSources>/<MediaCacheSource>/<Properties> container element.
<Property> <Name>awsAccessKeyId</Name> <Value>[access key ID]</Value> <Type>String</Type> </Property> <Property> <Name>awsSecretAccessKey</Name> <Value>[secret key]</Value> <Type>String</Type> </Property>
- ARN roles – Retrieves a set of temporary credentials that includes an access key ID, a secret access key, and a security token. To use this method, add the following properties to the <MediaCacheSources>
/<MediaCacheSource>/<Properties> container element.
Note: For more information on ARN Roles, see AssumeRole in the AWS documentation.
<Property> <Name>awsRoleSessionName</Name> <Value>[session name]</Value> <Type>String</Type> </Property> <Property> <Name>awsRoleARN</Name> <Value>[resource name]</Value> <Type>String</Type> </Property> <Property> <Name>awsAssumeRoleDuration</Name> <Value>3600</Value> <Type>String</Type> </Property> <Property> <Name>awsAccessKeyId</Name> <Value>[access key ID]</Value> <Type>String</Type> </Property> <Property> <Name>awsSecretAccessKey</Name> <Value>[secret key]</Value> <Type>String</Type> </Property>
Configure the HTTP client
By default, Wowza Streaming Engine uses the synchronous Apache HTTP client with the SDK. You can also use the built-in Java URLConnection. To configure the HTTP client, add the awsSDKHTTPClientType property to MediaCache.xml. The default value is 1. To specify URLConnection, set the value to 2.
Note: The Netty asynchronous HTTP client isn't supported.
- Navigate to [install-dir]/conf/ and open MediaCache.xml in a text editor.
- Add the awsSDKHTTPClientType property to the <MediaCacheSources>/<MediaCacheSource>
/<Properties> container element.
<Property> <Name>awsSDKHTTPClientType</Name> <Value>2</Value> <Type>Integer</Type> </Property>
- Restart Wowza Streaming Engine to apply the changes.
Tune the HTTP client
You can use the following properties to optimize the HTTP client’s performance:
Apache HTTP client properties
Path | Name | Type | Description |
/Root/MediaCacheSources /MediaCacheSource |
socketTimeout | Integer | The amount of time, in milliseconds, to wait for data to be transferred over an open connection. |
/Root/MediaCacheSources /MediaCacheSource |
connectionTimeout | Integer | The amount of time, in milliseconds, to wait for the connection to be established. |
/Root/MediaCacheSources /MediaCacheSource |
connectionAcquisitionTimeout | Integer | The amount of time, in milliseconds, to wait for a connection to be acquired. |
/Root/MediaCacheSources /MediaCacheSource |
maxConnections | Integer | The maximum number of connections allowed. |
/Root/MediaCacheSources /MediaCacheSource |
connectionTimeToLive | Integer | The maximum amount of time, in milliseconds, that a connection should be allowed to remain open. |
/Root/MediaCacheSources /MediaCacheSource |
connectionMaxIdleTime | Integer | The maximum amount of time, in milliseconds, that the connection is allowed to remain open while idle. |
/Root/MediaCacheSources /MediaCacheSource |
awsSDKUseIdleConnectionReaper | Boolean | If true, closes idle connections before the socket connection enters the CLOSE_WAIT state. |
/Root/MediaCacheSources /MediaCacheSource |
awsSDKExpectContinueEnabled | Boolean | If true, sends an HTTP expect-continue handshake before the request is made. |
URLConnection properties
Path | Name | Type | Description |
/Root/MediaCacheSources /MediaCacheSource |
socketTimeout | Integer | The amount of time, in milliseconds, to wait for data to be transferred over an open connection. |
/Root/MediaCacheSources /MediaCacheSource |
connectionTimeout | Integer | The amount of time, in milliseconds, to wait for the connection to be established. |