

# 使用 AWS CLI 的 CloudWatch Synthetics 示例
<a name="cli_synthetics_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface 与 CloudWatch Synthetics 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `associate-resource`
<a name="synthetics_AssociateResource_cli_topic"></a>

以下代码示例演示了如何使用 `associate-resource`。

**AWS CLI**  
**将金丝雀部署与组相关联**  
以下 `associate-resource` 示例将金丝雀部署与名为 `demo_group` 的组相关联。  

```
aws synthetics associate-resource \
    --group-identifier demo_group \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [AssociateResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/associate-resource.html)。

### `create-canary`
<a name="synthetics_CreateCanary_cli_topic"></a>

以下代码示例演示了如何使用 `create-canary`。

**AWS CLI**  
**创建金丝雀部署**  
以下 `create-canary` 示例创建名为 `demo_canary` 的金丝雀部署。  

```
aws synthetics create-canary \
    --name demo_canary \
    --code '{"S3Bucket": "artifacts3bucket", "S3Key":"demo_canary.zip", "Handler": "index.lambda_handler"}' \
    --artifact-s3-location s3://amzn-s3-demo-bucket/demo_canary.zip \
    --execution-role-arn arn:aws:iam::123456789012:role/demo_canary_role \
    --schedule Expression="rate(10 minutes)" \
    --runtime-version syn-nodejs-puppeteer-9.1
```
输出：  

```
{
    "Canary": {
        "Id": "a1b2c3d4-5678-90ab-cdef-example11111",
        "Name": "demo_canary",
        "Code": {
            "Handler": "index.lambda_handler"
        },
        "ExecutionRoleArn": "arn:aws:iam::123456789012:role/demo_canary_role",
        "Schedule": {
            "Expression": "rate(10 minutes)",
            "DurationInSeconds": 0
        },
        "RunConfig": {
            "TimeoutInSeconds": 600,
            "MemoryInMB": 1000,
            "ActiveTracing": false
        },
        "SuccessRetentionPeriodInDays": 31,
        "FailureRetentionPeriodInDays": 31,
        "Status": {
            "State": "CREATING",
            "StateReasonCode": "CREATE_PENDING"
        },
        "Timeline": {
            "Created": "2024-10-15T19:03:08.826000+05:30",
            "LastModified": "2024-10-15T19:03:08.826000+05:30"
        },
        "ArtifactS3Location": "amzn-s3-demo-bucket/demo_canary.zip",
        "RuntimeVersion": "syn-nodejs-puppeteer-9.1",
        "Tags": {}
    }
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [CreateCanary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/create-canary.html)。

### `create-group`
<a name="synthetics_CreateGroup_cli_topic"></a>

以下代码示例演示了如何使用 `create-group`。

**AWS CLI**  
**创建组**  
以下 `create-group` 示例创建名为 `demo_group` 的组。  

```
aws synthetics create-group \
    --name demo_group
```
输出：  

```
{
    "Group": {
        "Id": "example123",
        "Name": "demo_group",
        "Arn": "arn:aws:synthetics:us-east-1:123456789012:group:example123",
        "Tags": {},
        "CreatedTime": "2024-10-15T14:47:23.811000+05:30",
        "LastModifiedTime": "2024-10-15T14:47:23.811000+05:30"
    }
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/create-group.html)。

### `delete-canary`
<a name="synthetics_DeleteCanary_cli_topic"></a>

以下代码示例演示了如何使用 `delete-canary`。

**AWS CLI**  
**永久删除金丝雀部署**  
以下 `delete-canary` 示例删除名为 `demo_canary` 的金丝雀部署。  

```
aws synthetics delete-canary \
    --name demo_canary
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DeleteCanary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/delete-canary.html)。

### `delete-group`
<a name="synthetics_DeleteGroup_cli_topic"></a>

以下代码示例演示了如何使用 `delete-group`。

**AWS CLI**  
**删除组**  
以下 `delete-group` 示例删除名为 `demo_group` 的组。  

```
aws synthetics delete-group \
    --group-identifier demo_group
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/delete-group.html)。

### `describe-canaries-last-run`
<a name="synthetics_DescribeCanariesLastRun_cli_topic"></a>

以下代码示例演示了如何使用 `describe-canaries-last-run`。

**AWS CLI**  
**查看每个金丝雀部署的最近运行的相关信息**  
以下 `describe-canaries-last-run` 示例返回您创建的每个金丝雀部署的最近运行的相关信息。  

```
aws synthetics describe-canaries-last-run
```
输出：  

```
{
    "CanariesLastRun": [
        {
            "CanaryName": "demo_canary",
            "LastRun": {
                "Id": "a1b2c3d4-5678-90ab-cdef-example11111",
                "Name": "demo_canary",
                "Status": {
                    "State": "PASSED",
                    "StateReason": "",
                    "StateReasonCode": ""
                },
                "Timeline": {
                    "Started": "2024-10-15T19:20:39.691000+05:30",
                    "Completed": "2024-10-15T19:20:58.211000+05:30"
                },
                "ArtifactS3Location": "cw-syn-results-123456789012-us-east-1/canary/us-east-1/demo_canary-abc-example1234/2024/10/15/13/50-39-690"
            }
        }
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DescribeCanariesLastRun](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/describe-canaries-last-run.html)。

### `describe-canaries`
<a name="synthetics_DescribeCanaries_cli_topic"></a>

以下代码示例演示了如何使用 `describe-canaries`。

**AWS CLI**  
**列出您账户中的金丝雀部署**  
以下 `describe-canaries` 示例列出您账户中的金丝雀部署的详细信息。  

```
aws synthetics describe-canaries
```
输出：  

```
{
    "Canaries": [
        {
            "Id": "a1b2c3d4-5678-90ab-cdef-example11111",
            "Name": "demo_canary",
            "Code": {
                "SourceLocationArn": "arn:aws:lambda:us-east-1:123456789012:layer:cwsyn-demo_canary-a1b2c3d4-5678-90ab-cdef-example11111b8:1",
                "Handler": "pageLoadBlueprint.handler"
            },
            "ExecutionRoleArn": "arn:aws:iam::123456789012:role/service-role/CloudWatchSyntheticsRole-demo_canary-a12-a123bc456789",
            "Schedule": {
                "Expression": "rate(5 minutes)",
                "DurationInSeconds": 0
            },
            "RunConfig": {
                "TimeoutInSeconds": 300,
                "MemoryInMB": 1000,
                "ActiveTracing": false
            },
            "SuccessRetentionPeriodInDays": 31,
            "FailureRetentionPeriodInDays": 31,
            "Status": {
            "State": "RUNNING"
            },
            "Timeline": {
                "Created": "2024-10-15T18:55:15.168000+05:30",
                "LastModified": "2024-10-15T18:55:40.540000+05:30",
                "LastStarted": "2024-10-15T18:55:40.540000+05:30"
            },
            "ArtifactS3Location": "cw-syn-results-123456789012-us-east-1/canary/us-east-1/demo_canary-a12-a123bc456789",
            "EngineArn": "arn:aws:lambda:us-east-1:123456789012:function:cwsyn-demo_canary-a1b2c3d4-5678-90ab-cdef-example111118:1",
            "RuntimeVersion": "syn-nodejs-puppeteer-9.1",
            "Tags": {
                "blueprint": "heartbeat"
            }
        }
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DescribeCanaries](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/describe-canaries.html)。

### `describe-runtime-versions`
<a name="synthetics_DescribeRuntimeVersions_cli_topic"></a>

以下代码示例演示了如何使用 `describe-runtime-versions`。

**AWS CLI**  
**返回 Synthetics 金丝雀部署运行时版本的列表**  
以下 `describe-runtime-versions` 示例返回 Synthetics 金丝雀部署运行时版本的列表。  

```
aws synthetics describe-runtime-versions
```
输出：  

```
{
    "RuntimeVersions": [
        {
            "VersionName": "syn-nodejs-puppeteer-9.1",
            "Description": "Security fixes and bug fix for date range error in har. Dependencies: Node JS 20.x, Puppeteer-core 22.12.1, Chromium 126.0.6478.126",
            "ReleaseDate": "2024-10-02T05:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-9.0",
            "Description": "Upgraded Chromium and Puppeteer. Dependencies: Node JS 20.x, Puppeteer-core 22.12.1, Chromium 126.0.6478.126",
            "ReleaseDate": "2024-07-22T05:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-8.0",
            "Description": "Upgraded Chromium and Puppeteer. Dependencies: Node JS 20.x, Puppeteer-core 22.10.0, Chromium 125.0.6422.112",
            "ReleaseDate": "2024-06-21T05:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-7.0",
            "Description": "Upgraded Chromium and Puppeteer. Dependencies: Node JS 18.x, Puppeteer-core 21.9.0, Chromium 121.0.6167.139",
            "ReleaseDate": "2024-03-08T05:30:00+05:30"
            },
        {
            "VersionName": "syn-nodejs-puppeteer-6.2",
            "Description": "Updated shared libraries for Chromium and added ephemeral storage monitoring. Dependencies: Node JS 18.x, Puppeteer-core 19.7.0, Chromium 111.0.5563.146",
            "ReleaseDate": "2024-02-02T05:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-6.1",
            "Description": "Added puppeteer launch retry. Dependencies: Node JS 18.x, Puppeteer-core 19.7.0, Chromium 111.0.5563.146",
            "ReleaseDate": "2023-11-13T05:30:00+05:30",
            "DeprecationDate": "2024-03-08T13:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-6.0",
            "Description": "Reduced X-Ray traces of a canary run, improved duration metric and upgraded to NodeJS 18.x. Dependencies: Node JS 18.x, Puppeteer-core 19.7.0, Chromium 111.0.5563.146",
            "ReleaseDate": "2023-09-15T05:30:00+05:30",
            "DeprecationDate": "2024-03-08T13:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-5.2",
            "Description": "Updated shared libraries for Chromium. Dependencies: Node JS 16.x, Puppeteer-core 19.7.0, Chromium 111.0.5563.146",
            "ReleaseDate": "2024-02-01T05:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-5.1",
            "Description": "Fixes a bug about missing request headers in har. Dependencies: Node JS 16.x, Puppeteer-core 19.7.0, Chromium 111.0.5563.146",
            "ReleaseDate": "2023-08-09T05:30:00+05:30",
            "DeprecationDate": "2024-03-08T13:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-5.0",
            "Description": "Upgraded Puppeteer and Chromium. Dependencies: Node JS 16.x, Puppeteer-core 19.7.0, Chromium 111.0.5563.146",
            "ReleaseDate": "2023-07-21T05:30:00+05:30",
            "DeprecationDate": "2024-03-08T13:30:00+05:30"
        },
        {
            "VersionName": "syn-nodejs-puppeteer-4.0",
            "Description": "Upgraded to NodeJS 16.x. Dependencies: Node JS 16.x, Puppeteer-core 5.5.0, Chromium 92.0.4512.0",
            "ReleaseDate": "2023-05-01T05:30:00+05:30",
            "DeprecationDate": "2024-03-08T13:30:00+05:30"
        }
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DescribeRuntimeVersions](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/describe-runtime-versions.html)。

### `disassociate-resource`
<a name="synthetics_DisassociateResource_cli_topic"></a>

以下代码示例演示了如何使用 `disassociate-resource`。

**AWS CLI**  
**从组中移除金丝雀部署**  
以下 `disassociate-resource` 示例从名为 `demo_group` 的组中移除金丝雀部署。  

```
aws synthetics disassociate-resource \
    --group-identifier demo_group \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [DisassociateResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/disassociate-resource.html)。

### `get-canary-runs`
<a name="synthetics_GetCanaryRuns_cli_topic"></a>

以下代码示例演示了如何使用 `get-canary-runs`。

**AWS CLI**  
**检索指定金丝雀部署的运行列表**  
以下 `get-canary-runs` 示例检索名为 `demo_canary` 的金丝雀部署的运行列表。  

```
aws synthetics get-canary-runs \
    --name demo_canary
```
输出：  

```
{
    "CanaryRuns": [
        {
            "Id": "a1b2c3d4-5678-90ab-cdef-example11111",
            "Name": "demo_canary",
            "Status": {
                "State": "PASSED",
                "StateReason": "",
                "StateReasonCode": ""
            },
            "Timeline": {
                "Started": "2024-10-16T10:38:57.013000+05:30",
                "Completed": "2024-10-16T10:39:25.793000+05:30"
            },
            "ArtifactS3Location": "cw-syn-results-123456789012-us-east-1/canary/us-east-1/demo_canary-abc-example1234/2024/10/15/13/50-39-690"
        }
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [GetCanaryRuns](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/get-canary-runs.html)。

### `get-canary`
<a name="synthetics_GetCanary_cli_topic"></a>

以下代码示例演示了如何使用 `get-canary`。

**AWS CLI**  
**检索有关某个金丝雀部署的完整信息**  
以下 `get-canary` 示例检索有关名为 `demo_canary` 的金丝雀部署的完整信息。  

```
aws synthetics get-canary \
    --name demo_canary
```
输出：  

```
{
    "Canary": {
        "Id": "a1b2c3d4-5678-90ab-cdef-example11111",
        "Name": "demo_canary",
        "Code": {
            "SourceLocationArn": "arn:aws:lambda:us-east-1:123456789012:layer:cwsyn-demo_canary-a1b2c3d4-5678-90ab-cdef-example111118:1",
            "Handler": "pageLoadBlueprint.handler"
        },
        "ExecutionRoleArn": "arn:aws:iam::123456789012:role/demo_canary_role",
        "Schedule": {
            "Expression": "rate(10 minutes)",
            "DurationInSeconds": 0
        },
        "RunConfig": {
            "TimeoutInSeconds": 300,
            "MemoryInMB": 1000,
            "ActiveTracing": false
        },
        "SuccessRetentionPeriodInDays": 31,
        "FailureRetentionPeriodInDays": 31,
        "Status": {
            "State": "RUNNING"
        },
        "Timeline": {
            "Created": "2024-10-15T18:55:15.168000+05:30",
            "LastModified": "2024-10-15T18:55:40.540000+05:30",
            "LastStarted": "2024-10-15T18:55:40.540000+05:30"
        },
        "ArtifactS3Location": "cw-syn-results-123456789012-us-east-1/canary/us-east-1/demo_canary-a12-a123bc456789",
        "EngineArn": "arn:aws:lambda:us-east-1:123456789012:function:cwsyn-demo_canary-a1b2c3d4-5678-90ab-cdef-example111118:1",
        "RuntimeVersion": "syn-nodejs-puppeteer-9.1",
        "Tags": {
            "blueprint": "heartbeat"
        }
    }
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [GetCanary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/get-canary.html)。

### `get-group`
<a name="synthetics_GetGroup_cli_topic"></a>

以下代码示例演示了如何使用 `get-group`。

**AWS CLI**  
**返回有关某个组的信息**  
以下 `get-group` 示例返回有关名为 `demo_group` 的组的信息。  

```
aws synthetics get-group \
    --group-identifier demo_group
```
输出：  

```
{
    "Group": {
        "Id": "example123",
        "Name": "demo_group",
        "Arn": "arn:aws:synthetics:us-east-1:123456789012:group:example123",
        "Tags": {},
        "CreatedTime": "2024-10-15T14:47:23.811000+05:30",
        "LastModifiedTime": "2024-10-15T14:47:23.811000+05:30"
    }
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/get-group.html)。

### `list-associated-groups`
<a name="synthetics_ListAssociatedGroups_cli_topic"></a>

以下代码示例演示了如何使用 `list-associated-groups`。

**AWS CLI**  
**返回组列表**  
以下 `list-associated-groups` 示例返回与名为 `demo_canary` 的金丝雀部署关联的组的列表。  

```
aws synthetics list-associated-groups \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary
```
输出：  

```
{
    "Groups": [
        {
            "Id": "example123",
            "Name": "demo_group",
            "Arn": "arn:aws:synthetics:us-east-1:123456789012:group:example123"
        }
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [ListAssociatedGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/list-associated-groups.html)。

### `list-group-resources`
<a name="synthetics_ListGroupResources_cli_topic"></a>

以下代码示例演示了如何使用 `list-group-resources`。

**AWS CLI**  
**返回与指定组关联的金丝雀部署的 ARN 列表**  
以下 `list-group-resources` 示例返回与名为 `demo_group` 的组关联的金丝雀部署的 ARN 列表。  

```
aws synthetics list-group-resources \
    --group-identifier demo_group
```
输出：  

```
{
    "Resources": [
        "arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary"
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》中的 [ListGroupResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/list-group-resources.html)**。

### `list-groups`
<a name="synthetics_ListGroups_cli_topic"></a>

以下代码示例演示了如何使用 `list-groups`。

**AWS CLI**  
**返回账户中所有组的列表**  
以下 `list-groups` 示例返回账户中所有组的列表。  

```
aws synthetics list-groups
```
输出：  

```
{
    "Groups": [
        {
            "Id": "example123",
            "Name": "demo_group",
            "Arn": "arn:aws:synthetics:us-east-1:123456789012:group:example123"
        }
    ]
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/list-groups.html)。

### `list-tags-for-resource`
<a name="synthetics_ListTagsForResource_cli_topic"></a>

以下代码示例演示了如何使用 `list-tags-for-resource`。

**AWS CLI**  
**示例 1：显示与金丝雀部署关联的标签**  
以下 `list-tags-for-resource` 示例返回与名为 `demo_canary` 的金丝雀部署关联的标签。  

```
aws synthetics list-tags-for-resource \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary
```
输出：  

```
{
    "Tags": {
        "blueprint": "heartbeat"
    }
}
```
**示例 2：显示与组关联的标签**  
以下 `list-tags-for-resource` 示例返回与名为 `demo_group` 的组关联的标签。  

```
aws  synthetics list-tags-for-resource \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:group:example123
```
输出：  

```
{
    "Tags": {
        "team": "Devops"
    }
}
```
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/list-tags-for-resource.html)。

### `start-canary`
<a name="synthetics_StartCanary_cli_topic"></a>

以下代码示例演示了如何使用 `start-canary`。

**AWS CLI**  
**运行金丝雀部署**  
以下 `start-canary` 示例运行名为 `demo_canary` 的金丝雀部署。  

```
aws synthetics start-canary \
    --name demo_canary
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [StartCanary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/start-canary.html)。

### `stop-canary`
<a name="synthetics_StopCanary_cli_topic"></a>

以下代码示例演示了如何使用 `stop-canary`。

**AWS CLI**  
**停止金丝雀部署**  
以下 `stop-canary` 示例停止名为 `demo_canary` 的金丝雀部署。  

```
aws synthetics stop-canary \
    --name demo_canary
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [StopCanary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/stop-canary.html)。

### `tag-resource`
<a name="synthetics_TagResource_cli_topic"></a>

以下代码示例演示了如何使用 `tag-resource`。

**AWS CLI**  
**示例 1：为金丝雀部署分配标签**  
以下 `tag-resource` 示例为名为 `demo_canary` 的金丝雀部署分配标签。  

```
aws synthetics tag-resource \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary \
    --tags blueprint=heartbeat
```
此命令不生成任何输出。  
**示例 2：为组分配标签**  
以下 `tag-resource` 示例为名为 `demo_group` 的组分配标签。  

```
aws synthetics tag-resource \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:group:example123 \
    --tags team=Devops
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/tag-resource.html)。

### `untag-resource`
<a name="synthetics_UntagResource_cli_topic"></a>

以下代码示例演示了如何使用 `untag-resource`。

**AWS CLI**  
**示例 1：从金丝雀部署中移除标签**  
以下 `untag-resource` 示例从名为 `demo_canary` 的金丝雀部署中移除标签。  

```
aws synthetics untag-resource \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:canary:demo_canary \
    --tag-keys blueprint
```
此命令不生成任何输出。  
**示例 2：从组中移除标签**  
以下 `untag-resource` 示例从名为 `demo_group` 的组中移除标签。  

```
aws synthetics untag-resource \
    --resource-arn arn:aws:synthetics:us-east-1:123456789012:group:example123 \
    --tag-keys team
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/untag-resource.html)。

### `update-canary`
<a name="synthetics_UpdateCanary_cli_topic"></a>

以下代码示例演示了如何使用 `update-canary`。

**AWS CLI**  
**更新金丝雀部署**  
以下 `update-canary` 示例更新名为 `demo_canary` 的金丝雀部署的配置。  

```
aws synthetics update-canary \
    --name demo_canary \
    --schedule Expression="rate(15 minutes)"
```
此命令不生成任何输出。  
有关更多信息，请参阅《Amazon CloudWatch 用户指南》**中的[综合监控（金丝雀部署）](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html)。  
+  有关 API 详细信息，请参阅《AWS CLI Command Reference》**中的 [UpdateCanary](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/synthetics/update-canary.html)。