

There are more AWS SDK examples available in the [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) GitHub repo.

# Code examples for MediaPackage using AWS SDKs
<a name="mediapackage_code_examples"></a>

The following code examples show you how to use AWS Elemental MediaPackage with an AWS software development kit (SDK).

*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.

**More resources**
+  **[ MediaPackage User Guide](https://docs.aws.amazon.com/mediapackage/latest/ug/what-is.html)** – More information about MediaPackage.
+ **[MediaPackage API Reference](https://docs.aws.amazon.com/mediapackage/latest/apireference/what-is.html)** – Details about all available MediaPackage actions.
+ **[AWS Developer Center](https://aws.amazon.com/developer/code-examples/?awsf.sdk-code-examples-product=product%23elemental-mediapackage)** – Code examples that you can filter by category or full-text search.
+ **[AWS SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples)** – GitHub repo with complete code in preferred languages. Includes instructions for setting up and running the code.

**Contents**
+ [Basics](mediapackage_code_examples_basics.md)
  + [Actions](mediapackage_code_examples_actions.md)
    + [`ListChannels`](mediapackage_example_mediapackage_ListChannels_section.md)
    + [`ListOriginEndpoints`](mediapackage_example_mediapackage_ListOriginEndpoints_section.md)

# Basic examples for MediaPackage using AWS SDKs
<a name="mediapackage_code_examples_basics"></a>

The following code examples show how to use the basics of AWS Elemental MediaPackage with AWS SDKs. 

**Contents**
+ [Actions](mediapackage_code_examples_actions.md)
  + [`ListChannels`](mediapackage_example_mediapackage_ListChannels_section.md)
  + [`ListOriginEndpoints`](mediapackage_example_mediapackage_ListOriginEndpoints_section.md)

# Actions for MediaPackage using AWS SDKs
<a name="mediapackage_code_examples_actions"></a>

The following code examples demonstrate how to perform individual MediaPackage actions with AWS SDKs. Each example includes a link to GitHub, where you can find instructions for setting up and running the code. 

 The following examples include only the most commonly used actions. For a complete list, see the [AWS Elemental MediaPackage API Reference](https://docs.aws.amazon.com/mediapackage/latest/apireference/what-is.html). 

**Topics**
+ [`ListChannels`](mediapackage_example_mediapackage_ListChannels_section.md)
+ [`ListOriginEndpoints`](mediapackage_example_mediapackage_ListOriginEndpoints_section.md)

# Use `ListChannels` with an AWS SDK or CLI
<a name="mediapackage_example_mediapackage_ListChannels_section"></a>

The following code examples show how to use `ListChannels`.

------
#### [ CLI ]

**AWS CLI**  
**To list all channels**  
The following `list-channels` command lists all of the channels that are configured on the current AWS account.  

```
aws mediapackage list-channels
```
Output:  

```
{
    "Channels": [
        {
            "Arn": "arn:aws:mediapackage:us-west-2:111222333:channels/584797f1740548c389a273585dd22a63",
            "HlsIngest": {
                "IngestEndpoints": [
                    {
                        "Id": "584797f1740548c389a273585dd22a63",
                        "Password": "webdavgeneratedpassword1",
                        "Url": "https://9be9c4405c474882.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/584797f1740548c389a273585dd22a63/channel",
                        "Username": "webdavgeneratedusername1"
                    },
                    {
                        "Id": "7d187c8616fd455f88aaa5a9fcf74442",
                        "Password": "webdavgeneratedpassword2",
                        "Url": "https://7bf454c57220328d.mediapackage.us-west-2.amazonaws.com/in/v2/584797f1740548c389a273585dd22a63/7d187c8616fd455f88aaa5a9fcf74442/channel",
                        "Username": "webdavgeneratedusername2"
                    }
                ]
            },
            "Id": "test",
            "Tags": {}
        }
    ]
}
```
For more information, see [Viewing Channel Details](https://docs.aws.amazon.com/mediapackage/latest/ug/channels-view.html) in the *AWS Elemental MediaPackage User Guide*.  
+  For API details, see [ListChannels](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/mediapackage/list-channels.html) in *AWS CLI Command Reference*. 

------
#### [ Rust ]

**SDK for Rust**  
 There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/mediapackage#code-examples). 
List channel ARNs and descriptions.  

```
async fn show_channels(client: &Client) -> Result<(), Error> {
    let list_channels = client.list_channels().send().await?;

    println!("Channels:");

    for c in list_channels.channels() {
        let description = c.description().unwrap_or_default();
        let arn = c.arn().unwrap_or_default();

        println!("  Description : {}", description);
        println!("  ARN :         {}", arn);
        println!();
    }

    Ok(())
}
```
+  For API details, see [ListChannels](https://docs.rs/aws-sdk-mediapackage/latest/aws_sdk_mediapackage/client/struct.Client.html#method.list_channels) in *AWS SDK for Rust API reference*. 

------

# Use `ListOriginEndpoints` with an AWS SDK or CLI
<a name="mediapackage_example_mediapackage_ListOriginEndpoints_section"></a>

The following code examples show how to use `ListOriginEndpoints`.

------
#### [ CLI ]

**AWS CLI**  
**To list all origin-endpoints on a channel**  
The following `list-origin-endpoints` command lists all of the origin endpoints that are configured on the channel named `test`.  

```
aws mediapackage list-origin-endpoints \
    --channel-id test
```
Output:  

```
{
    "OriginEndpoints": [
        {
            "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/247cff871f2845d3805129be22f2c0a2",
            "ChannelId": "test",
            "DashPackage": {
                "ManifestLayout": "FULL",
                "ManifestWindowSeconds": 60,
                "MinBufferTimeSeconds": 30,
                "MinUpdatePeriodSeconds": 15,
                "PeriodTriggers": [],
                "Profile": "NONE",
                "SegmentDurationSeconds": 2,
                "SegmentTemplateFormat": "NUMBER_WITH_TIMELINE",
                "StreamSelection": {
                    "MaxVideoBitsPerSecond": 2147483647,
                    "MinVideoBitsPerSecond": 0,
                    "StreamOrder": "ORIGINAL"
                },
                "SuggestedPresentationDelaySeconds": 25
            },
            "Id": "tester2",
            "ManifestName": "index",
            "StartoverWindowSeconds": 0,
            "Tags": {},
            "TimeDelaySeconds": 0,
            "Url": "https://8343f7014c0ea438.mediapackage.us-west-2.amazonaws.com/out/v1/247cff871f2845d3805129be22f2c0a2/index.mpd",
            "Whitelist": []
        },
        {
            "Arn": "arn:aws:mediapackage:us-west-2:111222333:origin_endpoints/869e237f851549e9bcf10e3bc2830839",
            "ChannelId": "test",
            "HlsPackage": {
                "AdMarkers": "NONE",
                "IncludeIframeOnlyStream": false,
                "PlaylistType": "EVENT",
                "PlaylistWindowSeconds": 60,
                "ProgramDateTimeIntervalSeconds": 0,
                "SegmentDurationSeconds": 6,
                "StreamSelection": {
                    "MaxVideoBitsPerSecond": 2147483647,
                    "MinVideoBitsPerSecond": 0,
                    "StreamOrder": "ORIGINAL"
                },
                "UseAudioRenditionGroup": false
            },
            "Id": "tester",
            "ManifestName": "index",
            "StartoverWindowSeconds": 0,
            "Tags": {},
            "TimeDelaySeconds": 0,
            "Url": "https://8343f7014c0ea438.mediapackage.us-west-2.amazonaws.com/out/v1/869e237f851549e9bcf10e3bc2830839/index.m3u8",
            "Whitelist": []
        }
    ]
}
```
For more information, see [Viewing all Endpoints Associated with a Channel](https://docs.aws.amazon.com/mediapackage/latest/ug/endpoints-view-all.html) in the *AWS Elemental MediaPackage User Guide*.  
+  For API details, see [ListOriginEndpoints](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/mediapackage/list-origin-endpoints.html) in *AWS CLI Command Reference*. 

------
#### [ Rust ]

**SDK for Rust**  
 There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/mediapackage#code-examples). 
List your endpoint descriptions and URLs.  

```
async fn show_endpoints(client: &Client) -> Result<(), Error> {
    let or_endpoints = client.list_origin_endpoints().send().await?;

    println!("Endpoints:");

    for e in or_endpoints.origin_endpoints() {
        let endpoint_url = e.url().unwrap_or_default();
        let endpoint_description = e.description().unwrap_or_default();
        println!("  Description: {}", endpoint_description);
        println!("  URL :        {}", endpoint_url);
        println!();
    }

    Ok(())
}
```
+  For API details, see [ListOriginEndpoints](https://docs.rs/aws-sdk-mediapackage/latest/aws_sdk_mediapackage/client/struct.Client.html#method.list_origin_endpoints) in *AWS SDK for Rust API reference*. 

------