View a markdown version of this page

MediaStore examples using AWS CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

MediaStore examples using AWS CLI

The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with MediaStore.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use create-container.

AWS CLI

To create a container

The following create-container example creates a new, empty container.

aws mediastore create-container \ --container-name ExampleContainer

Output:

{ "Container": { "AccessLoggingEnabled": false, "CreationTime": 1563557265, "Name": "ExampleContainer", "Status": "CREATING", "ARN": "arn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer" } }

The following code example shows how to use delete-container-policy.

AWS CLI

To delete a container policy

The following delete-container-policy example deletes the policy that is assigned to the specified container. When the policy is deleted, AWS Elemental MediaStore automatically assigns the default policy to the container.

aws mediastore delete-container-policy \ --container-name LiveEvents

This command produces no output.

The following code example shows how to use delete-container.

AWS CLI

To delete a container

The following delete-container example deletes the specified container. You can delete a container only if it has no objects.

aws mediastore delete-container \ --container-name=ExampleLiveDemo

This command produces no output.

The following code example shows how to use delete-cors-policy.

AWS CLI

To delete a CORS policy

The following delete-cors-policy example deletes the cross-origin resource sharing (CORS) policy that is assigned to the specified container.

aws mediastore delete-cors-policy \ --container-name ExampleContainer

This command produces no output.

The following code example shows how to use delete-lifecycle-policy.

AWS CLI

To delete an object lifecycle policy

The following delete-lifecycle-policy example deletes the object lifecycle policy attached to the specified container. This change can take up to 20 minutes to take effect.

aws mediastore delete-lifecycle-policy \ --container-name LiveEvents

This command produces no output.

The following code example shows how to use describe-container.

AWS CLI

To view the details of a container

The following describe-container example displays the details of the specified container.

aws mediastore describe-container \ --container-name ExampleContainer

Output:

{ "Container": { "CreationTime": 1563558086, "AccessLoggingEnabled": false, "ARN": "arn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer", "Status": "ACTIVE", "Name": "ExampleContainer", "Endpoint": "https://aaabbbcccdddee.data.mediastore.us-west-2.amazonaws.com" } }

The following code example shows how to use get-container-policy.

AWS CLI

To view a container policy

The following get-container-policy example displays the resource-based policy of the specified container.

aws mediastore get-container-policy \ --container-name ExampleLiveDemo

Output:

{ "Policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"PublicReadOverHttps\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:root\"},\"Action\":[\"mediastore:GetObject\",\"mediastore:DescribeObject\"],\"Resource\":\"arn:aws:mediastore:us-west-2:123456789012:container/ExampleLiveDemo/\",\"Condition\":{\"Bool\":{\"aws:SecureTransport\":\"true\"}}}]}" }

The following code example shows how to use get-cors-policy.

AWS CLI

To view a CORS policy

The following get-cors-policy example displays the cross-origin resource sharing (CORS) policy that is assigned to the specified container.

aws mediastore get-cors-policy \ --container-name ExampleContainer

Output:

{ "CorsPolicy": [ { "AllowedMethods": [ "GET", "HEAD" ], "MaxAgeSeconds": 3000, "AllowedOrigins": [ "" ], "AllowedHeaders": [ "" ] } ] }
  • For API details, see GetCorsPolicy in AWS CLI Command Reference.

The following code example shows how to use get-lifecycle-policy.

AWS CLI

To view an object lifecycle policy

The following get-lifecycle-policy example displays the object lifecycle policy attached to the specified container.

aws mediastore get-lifecycle-policy \ --container-name LiveEvents

Output:

{ "LifecyclePolicy": "{\"rules\":[{\"definition\":{\"path\":[{\"prefix\":\"Football/\"},{\"prefix\":\"Baseball/\"}],\"days_since_create\":[{\"numeric\":[\">\",28]}]},\"action\":\"EXPIRE\"}]}" }

The following code example shows how to use list-containers.

AWS CLI

To view a list of containers

The following list-containers example displays a list of all containers that are associated with your account.

aws mediastore list-containers

Output:

{ "Containers": [ { "CreationTime": 1505317931, "Endpoint": "https://aaabbbcccdddee.data.mediastore.us-west-2.amazonaws.com", "Status": "ACTIVE", "ARN": "arn:aws:mediastore:us-west-2:123456789012:container/ExampleLiveDemo", "AccessLoggingEnabled": false, "Name": "ExampleLiveDemo" }, { "CreationTime": 1506528818, "Endpoint": "https://fffggghhhiiijj.data.mediastore.us-west-2.amazonaws.com", "Status": "ACTIVE", "ARN": "arn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer", "AccessLoggingEnabled": false, "Name": "ExampleContainer" } ] }

The following code example shows how to use list-tags-for-resource.

AWS CLI

To list tags for a container

The following list-tags-for-resource example displays the tag keys and values assigned to the specified container.

aws mediastore list-tags-for-resource \ --resource arn:aws:mediastore:us-west-2:1213456789012:container/ExampleContainer

Output:

{ "Tags": [ { "Value": "Test", "Key": "Environment" }, { "Value": "West", "Key": "Region" } ] }

For more information, see Best practices and strategies in the Tagging AWS Resources and Tag Editor User Guide.

The following code example shows how to use put-container-policy.

AWS CLI

To edit a container policy

The following put-container-policy example assigns a different policy to the specified container. In this example, the updated policy is defined in a file named LiveEventsContainerPolicy.json.

aws mediastore put-container-policy \ --container-name LiveEvents \ --policy file://LiveEventsContainerPolicy.json

Contents of LiveEventsContainerPolicy.json:

{ "Version":"2012-10-17", "Statement": [ { "Sid": "MediaStoreFullAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:root" }, "Action": "mediastore:*", "Resource": "arn:aws:mediastore:us-west-2:123456789012:container/LiveEvents/*", "Condition": { "Bool": { "aws:SecureTransport": "true" } } } ] }

This command produces no output.

The following code example shows how to use put-cors-policy.

AWS CLI

Example 1: To add a CORS policy

The following put-cors-policy example adds a cross-origin resource sharing (CORS) policy to the specified container. The contents of the CORS policy are in the file named corsPolicy.json.

aws mediastore put-cors-policy \ --container-name ExampleContainer \ --cors-policy file://corsPolicy.json

Contents of corsPolicy.json:

[ { "AllowedOrigins": [ "https://www.example.com" ], "AllowedMethods": [ "GET", "HEAD" ], "AllowedHeaders": [ "*" ], "MaxAgeSeconds": 3000 } ]

This command produces no output.

Example 2: To edit a CORS policy

The following put-cors-policy example updates the cross-origin resource sharing (CORS) policy that is assigned to the specified container. The contents of the updated CORS policy are in the file named corsPolicy2.json.

  • For API details, see PutCorsPolicy in AWS CLI Command Reference.

The following code example shows how to use put-lifecycle-policy.

AWS CLI

To create an object lifecycle policy

The following put-lifecycle-policy example attaches an object lifecycle policy to the specified container. This enables you to specify how long the service should store objects in your container. MediaStore deletes objects in the container once they reach their expiration date, as indicated in the policy, which is in the file named ExampleLifecyclePolicy.json.

aws mediastore put-lifecycle-policy \ --container-name ExampleContainer \ --lifecycle-policy file://ExampleLifecyclePolicy.json

Contents of ExampleLifecyclePolicy.json:

{ "rules": [ { "definition": { "path": [ {"prefix": "Football/"}, {"prefix": "Baseball/"} ], "days_since_create": [ {"numeric": [">", 28]} ] }, "action": "EXPIRE" } ] }

This command produces no output.

The following code example shows how to use start-access-logging.

AWS CLI

To enable access logging on a container

The following start-access-logging example enable access logging on the specified container.

aws mediastore start-access-logging \ --container-name LiveEvents

This command produces no output.

The following code example shows how to use stop-access-logging.

AWS CLI

To disable access logging on a container

The following stop-access-logging example disables access logging on the specified container.

aws mediastore stop-access-logging \ --container-name LiveEvents

This command produces no output.

The following code example shows how to use tag-resource.

AWS CLI

To add tags to a container

The following tag-resource example adds tag keys and values to the specified container.

aws mediastore tag-resource \ --resource arn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer \ --tags '[{"Key": "Region", "Value": "West"}, {"Key": "Environment", "Value": "Test"}]'

This command produces no output.

For more information, see Best practices and strategies in the Tagging AWS Resources and Tag Editor User Guide.

  • For API details, see TagResource in AWS CLI Command Reference.

The following code example shows how to use untag-resource.

AWS CLI

To remove tags from a container

The following untag-resource example removes the specified tag key and its associated value from a container.

aws mediastore untag-resource \ --resource arn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer \ --tag-keys Region

This command produces no output.

For more information, see Best practices and strategies in the Tagging AWS Resources and Tag Editor User Guide.

  • For API details, see UntagResource in AWS CLI Command Reference.