There are more AWS SDK examples available in the AWS Doc SDK Examples
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-containerexample creates a new, empty container.aws mediastore create-container \ --container-nameExampleContainerOutput:
{ "Container": { "AccessLoggingEnabled": false, "CreationTime": 1563557265, "Name": "ExampleContainer", "Status": "CREATING", "ARN": "arn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer" } }-
For API details, see CreateContainer
in AWS CLI Command Reference.
-
The following code example shows how to use delete-container-policy.
- AWS CLI
-
To delete a container policy
The following
delete-container-policyexample 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-nameLiveEventsThis command produces no output.
-
For API details, see DeleteContainerPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use delete-container.
- AWS CLI
-
To delete a container
The following
delete-containerexample deletes the specified container. You can delete a container only if it has no objects.aws mediastore delete-container \ --container-name=ExampleLiveDemoThis command produces no output.
-
For API details, see DeleteContainer
in AWS CLI Command Reference.
-
The following code example shows how to use delete-cors-policy.
- AWS CLI
-
To delete a CORS policy
The following
delete-cors-policyexample deletes the cross-origin resource sharing (CORS) policy that is assigned to the specified container.aws mediastore delete-cors-policy \ --container-nameExampleContainerThis command produces no output.
-
For API details, see DeleteCorsPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use delete-lifecycle-policy.
- AWS CLI
-
To delete an object lifecycle policy
The following
delete-lifecycle-policyexample 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-nameLiveEventsThis command produces no output.
-
For API details, see DeleteLifecyclePolicy
in AWS CLI Command Reference.
-
The following code example shows how to use describe-container.
- AWS CLI
-
To view the details of a container
The following
describe-containerexample displays the details of the specified container.aws mediastore describe-container \ --container-nameExampleContainerOutput:
{ "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" } }-
For API details, see DescribeContainer
in AWS CLI Command Reference.
-
The following code example shows how to use get-container-policy.
- AWS CLI
-
To view a container policy
The following
get-container-policyexample displays the resource-based policy of the specified container.aws mediastore get-container-policy \ --container-nameExampleLiveDemoOutput:
{ "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\"}}}]}" }-
For API details, see GetContainerPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use get-cors-policy.
- AWS CLI
-
To view a CORS policy
The following
get-cors-policyexample displays the cross-origin resource sharing (CORS) policy that is assigned to the specified container.aws mediastore get-cors-policy \ --container-nameExampleContainerOutput:
{ "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-policyexample displays the object lifecycle policy attached to the specified container.aws mediastore get-lifecycle-policy \ --container-nameLiveEventsOutput:
{ "LifecyclePolicy": "{\"rules\":[{\"definition\":{\"path\":[{\"prefix\":\"Football/\"},{\"prefix\":\"Baseball/\"}],\"days_since_create\":[{\"numeric\":[\">\",28]}]},\"action\":\"EXPIRE\"}]}" }-
For API details, see GetLifecyclePolicy
in AWS CLI Command Reference.
-
The following code example shows how to use list-containers.
- AWS CLI
-
To view a list of containers
The following
list-containersexample displays a list of all containers that are associated with your account.aws mediastore list-containersOutput:
{ "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" } ] }-
For API details, see ListContainers
in AWS CLI Command Reference.
-
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-resourceexample displays the tag keys and values assigned to the specified container.aws mediastore list-tags-for-resource \ --resourcearn:aws:mediastore:us-west-2:1213456789012:container/ExampleContainerOutput:
{ "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.
-
For API details, see ListTagsForResource
in AWS CLI Command Reference.
-
The following code example shows how to use put-container-policy.
- AWS CLI
-
To edit a container policy
The following
put-container-policyexample assigns a different policy to the specified container. In this example, the updated policy is defined in a file namedLiveEventsContainerPolicy.json.aws mediastore put-container-policy \ --container-nameLiveEvents\ --policyfile://LiveEventsContainerPolicy.jsonContents 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.
-
For API details, see PutContainerPolicy
in AWS CLI Command Reference.
-
The following code example shows how to use put-cors-policy.
- AWS CLI
-
Example 1: To add a CORS policy
The following
put-cors-policyexample adds a cross-origin resource sharing (CORS) policy to the specified container. The contents of the CORS policy are in the file namedcorsPolicy.json.aws mediastore put-cors-policy \ --container-nameExampleContainer\ --cors-policyfile://corsPolicy.jsonContents 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-policyexample 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 namedcorsPolicy2.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-policyexample 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 namedExampleLifecyclePolicy.json.aws mediastore put-lifecycle-policy \ --container-nameExampleContainer\ --lifecycle-policyfile://ExampleLifecyclePolicy.jsonContents of
ExampleLifecyclePolicy.json:{ "rules": [ { "definition": { "path": [ {"prefix": "Football/"}, {"prefix": "Baseball/"} ], "days_since_create": [ {"numeric": [">", 28]} ] }, "action": "EXPIRE" } ] }This command produces no output.
-
For API details, see PutLifecyclePolicy
in AWS CLI Command Reference.
-
The following code example shows how to use start-access-logging.
- AWS CLI
-
To enable access logging on a container
The following
start-access-loggingexample enable access logging on the specified container.aws mediastore start-access-logging \ --container-nameLiveEventsThis command produces no output.
-
For API details, see StartAccessLogging
in AWS CLI Command Reference.
-
The following code example shows how to use stop-access-logging.
- AWS CLI
-
To disable access logging on a container
The following
stop-access-loggingexample disables access logging on the specified container.aws mediastore stop-access-logging \ --container-nameLiveEventsThis command produces no output.
-
For API details, see StopAccessLogging
in AWS CLI Command Reference.
-
The following code example shows how to use tag-resource.
- AWS CLI
-
To add tags to a container
The following
tag-resourceexample adds tag keys and values to the specified container.aws mediastore tag-resource \ --resourcearn: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-resourceexample removes the specified tag key and its associated value from a container.aws mediastore untag-resource \ --resourcearn:aws:mediastore:us-west-2:123456789012:container/ExampleContainer\ --tag-keysRegionThis 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.
-