

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 搭配使用 `CreateSpotDatafeedSubscription` 與 CLI
<a name="ec2_example_ec2_CreateSpotDatafeedSubscription_section"></a>

下列程式碼範例示範如何使用 `CreateSpotDatafeedSubscription`。

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

**AWS CLI**  
**建立 Spot 執行個體資料饋送**  
下列 `create-spot-datafeed-subscription` 範例會建立 Spot 執行個體資料饋送。  

```
aws ec2 create-spot-datafeed-subscription \
    --bucket amzn-s3-demo-bucket \
    --prefix spot-data-feed
```
輸出：  

```
{
    "SpotDatafeedSubscription": {
        "Bucket": "amzn-s3-demo-bucket",
        "OwnerId": "123456789012",
        "Prefix": "spot-data-feed",
        "State": "Active"
    }
}
```
資料饋送會存放在您指定的 Amazon S3 儲存貯體中。此資料饋送的檔案名稱具有以下格式。  

```
amzn-s3-demo-bucket.s3.amazonaws.com/spot-data-feed/123456789012.YYYY-MM-DD-HH.n.abcd1234.gz
```
如需詳細資訊，請參閱《*Amazon EC2 使用者指南*》中的 [Spot 執行個體資料饋送](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-data-feeds.html)。  
+  如需 API 詳細資訊，請參閱《*AWS CLI 命令參考*》中的 [CreateSpotDatafeedSubscription](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/create-spot-datafeed-subscription.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會建立 Spot 執行個體資料饋送。**  

```
New-EC2SpotDatafeedSubscription -Bucket amzn-s3-demo-bucket -Prefix spotdata
```
**輸出：**  

```
Bucket  : amzn-s3-demo-bucket
Fault   :
OwnerId : 123456789012
Prefix  : spotdata
State   : Active
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [CreateSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會建立 Spot 執行個體資料饋送。**  

```
New-EC2SpotDatafeedSubscription -Bucket amzn-s3-demo-bucket -Prefix spotdata
```
**輸出：**  

```
Bucket  : amzn-s3-demo-bucket
Fault   :
OwnerId : 123456789012
Prefix  : spotdata
State   : Active
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateSpotDatafeedSubscription](https://docs.aws.amazon.com/powershell/v5/reference)。

------