

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

# 使用 的 VPC Lattice 範例 AWS CLI
<a name="cli_vpc-lattice_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 VPC Lattice 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

### `create-listener`
<a name="vpc-lattice_CreateListener_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-listener`。

**AWS CLI**  
**建立接聽程式**  
下列 `create-listener` 範例會使用預設規則建立 HTTPS 接聽程式，將流量轉送至指定的 VPC Lattice 目標群組。  

```
aws vpc-lattice create-listener \
    --name my-service-listener \
    --protocol HTTPS \
    --port 443 \
    --service-identifier svc-0285b53b2eEXAMPLE \
    --default-action file://listener-config.json
```
`listener-config.json` 的內容：  

```
{
    "forward": {
        "targetGroups": [
            {
                "targetGroupIdentifier": "tg-0eaa4b9ab4EXAMPLE"
            }
        ]
    }
}
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE/listener/listener-07cc7fb0abEXAMPLE",
    "defaultAction": {
        "forward": {
            "targetGroups": [
                {
                    "targetGroupIdentifier": "tg-0eaa4b9ab4EXAMPLE",
                    "weight": 100
                }
            ]
        }
    },
    "id": "listener-07cc7fb0abEXAMPLE",
    "name": "my-service-listener",
    "port": 443,
    "protocol": "HTTPS",
    "serviceArn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "serviceId": "svc-0285b53b2eEXAMPLE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[接聽程式](https://docs.aws.amazon.com/vpc-lattice/latest/ug/listeners.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateListener](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-listener.html)。

### `create-resource-configuration`
<a name="vpc-lattice_CreateResourceConfiguration_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-resource-configuration`。

**AWS CLI**  
**建立資源組態**  
下列 `create-resource-configuration` 範例會建立指定單一 IPv4 地址的資源組態。  

```
aws vpc-lattice create-resource-configuration \
    --name my-resource-config \
    --type SINGLE \
    --resource-gateway-identifier rgw-0bba03f3d56060135 \
    --resource-configuration-definition 'ipResource={ipAddress=10.0.14.85}'
```
輸出：  

```
{
    "allowAssociationToShareableServiceNetwork": true,
    "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourceconfiguration/rcfg-07129f3acded87625",
    "id": "rcfg-07129f3acded87625",
    "name": "my-resource-config",
    "portRanges": [
        "1-65535"
    ],
    "protocol": "TCP",
    "resourceConfigurationDefinition": {
        "ipResource": {
            "ipAddress": "10.0.14.85"
        }
    },
    "resourceGatewayId": "rgw-0bba03f3d56060135",
    "status": "ACTIVE",
    "type": "SINGLE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC 資源的資源組態](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-configuration.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateResourceConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-resource-configuration.html)。

### `create-resource-gateway`
<a name="vpc-lattice_CreateResourceGateway_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-resource-gateway`。

**AWS CLI**  
**建立資源閘道**  
下列 `create-resource-gateway` 範例會為指定的子網路建立資源閘道。  

```
aws vpc-lattice create-resource-gateway \
    --name my-resource-gateway \
    --vpc-identifier vpc-0bf4c2739bc05a69 \
    --subnet-ids subnet-08e8943905b63a683
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourcegateway/rgw-0bba03f3d56060135",
    "id": "rgw-0bba03f3d56060135",
    "ipAddressType": "IPV4",
    "name": "my-resource-gateway",
    "securityGroupIds": [
        "sg-087ffd596c5fe962c"
    ],
    "status": "ACTIVE",
    "subnetIds": [
        "subnet-08e8943905b63a683"
    ],
    "vpcIdentifier": "vpc-0bf4c2739bc05a694"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的資源閘道](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-gateway.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateResourceGateway](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-resource-gateway.html)。

### `create-service-network-service-association`
<a name="vpc-lattice_CreateServiceNetworkServiceAssociation_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-service-network-service-association`。

**AWS CLI**  
**建立服務關聯**  
下列 `create-service-network-service-association` 範例會將指定服務與指定服務網路建立關聯。  

```
aws vpc-lattice create-service-network-service-association \
    --service-identifier svc-0285b53b2eEXAMPLE \
    --service-network-identifier sn-080ec7dc93EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkserviceassociation/snsa-0e16955a8cEXAMPLE",
    "createdBy": "123456789012",
    "dnsEntry": {
        "domainName": "my-lattice-service-0285b53b2eEXAMPLE.7d67968.vpc-lattice-svcs.us-east-2.on.aws",
        "hostedZoneId": "Z09127221KTH2CEXAMPLE"
    },
    "id": "snsa-0e16955a8cEXAMPLE",
    "status": "CREATE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理服務關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-service-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateServiceNetworkServiceAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-service-network-service-association.html)。

### `create-service-network-vpc-association`
<a name="vpc-lattice_CreateServiceNetworkVpcAssociation_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-service-network-vpc-association`。

**AWS CLI**  
**建立 VPC 關聯**  
下列 `create-service-network-vpc-association` 範例會將指定的 vpc 與指定的服務網路建立關聯。指定的安全群組會控制 VPC 中的哪些資源可以存取服務網路及其服務。  

```
aws vpc-lattice create-service-network-vpc-association \
    --vpc-identifier vpc-0a1b2c3d4eEXAMPLE \
    --service-network-identifier sn-080ec7dc93EXAMPLE \
    --security-group-ids sg-0aee16bc6cEXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkvpcassociation/snva-0821fc8631EXAMPLE",
    "createdBy": "123456789012",
    "id": "snva-0821fc8631EXAMPLE",
    "securityGroupIds": [
        "sg-0aee16bc6cEXAMPLE"
    ],
    "status": "CREATE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理 VPC 關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-vpc-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateServiceNetworkVpcAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-service-network-vpc-association.html)。

### `create-service-network`
<a name="vpc-lattice_CreateServiceNetwork_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-service-network`。

**AWS CLI**  
**建立服務網路**  
下列 `create-service-network` 範例會建立具有指定名稱的服務網路。  

```
aws vpc-lattice create-service-network \
    --name my-service-network
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-080ec7dc93EXAMPLE",
    "authType": "NONE",
    "id": "sn-080ec7dc93EXAMPLE",
    "name": "my-service-network"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[服務網路](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-networks.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateServiceNetwork](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-service-network.html)。

### `create-service`
<a name="vpc-lattice_CreateService_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-service`。

**AWS CLI**  
**建立服務**  
下列 `create-service` 範例會建立具有指定名稱的服務。  

```
aws vpc-lattice create-service \
    --name my-lattice-service
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "authType": "NONE",
    "dnsEntry": {
        "domainName": "my-lattice-service-0285b53b2eEXAMPLE.1a2b3c4.vpc-lattice-svcs.us-east-2.on.aws",
        "hostedZoneId": "Z09127221KTH2CEXAMPLE"
    },
    "id": "svc-0285b53b2eEXAMPLE",
    "name": "my-lattice-service",
    "status": "CREATE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的服務](https://docs.aws.amazon.com/vpc-lattice/latest/ug/services.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateService](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-service.html)。

### `create-target-group`
<a name="vpc-lattice_CreateTargetGroup_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-target-group`。

**AWS CLI**  
**範例 1：建立類型為 INSTANCE 的目標群組**  
下列 `create-target-group` 範例會建立具有指定名稱、類型和組態的目標群組。  

```
aws vpc-lattice create-target-group \
    --name my-lattice-target-group-instance \
    --type INSTANCE \
    --config file://tg-config.json
```
`tg-config.json` 的內容：  

```
{
    "port": 443,
    "protocol": "HTTPS",
    "protocolVersion": "HTTP1",
    "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
}
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE",
    "config": {
        "healthCheck": {
            "enabled": true,
            "healthCheckIntervalSeconds": 30,
            "healthCheckTimeoutSeconds": 5,
            "healthyThresholdCount": 5,
            "matcher": {
                "httpCode": "200"
            },
            "path": "/",
            "protocol": "HTTPS",
            "protocolVersion": "HTTP1",
            "unhealthyThresholdCount": 2
        },
        "port": 443,
        "protocol": "HTTPS",
        "protocolVersion": "HTTP1",
        "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
    },
    "id": "tg-0eaa4b9ab4EXAMPLE",
    "name": "my-lattice-target-group-instance",
    "status": "CREATE_IN_PROGRESS",
    "type": "INSTANCE"
}
```
**範例 2：建立類型為 IP 的目標群組**  
下列 `create-target-group` 範例會建立具有指定名稱、類型和組態的目標群組。  

```
aws vpc-lattice create-target-group \
    --name my-lattice-target-group-ip \
    --type IP \
    --config file://tg-config.json
```
`tg-config.json` 的內容：  

```
{
    "ipAddressType": "IPV4",
    "port": 443,
    "protocol": "HTTPS",
    "protocolVersion": "HTTP1",
    "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
}
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE",
    "config": {
        "healthCheck": {
            "enabled": true,
            "healthCheckIntervalSeconds": 30,
            "healthCheckTimeoutSeconds": 5,
            "healthyThresholdCount": 5,
            "matcher": {
                "httpCode": "200"
            },
            "path": "/",
            "protocol": "HTTPS",
            "protocolVersion": "HTTP1",
            "unhealthyThresholdCount": 2
        },
        "ipAddressType": "IPV4",
        "port": 443,
        "protocol": "HTTPS",
        "protocolVersion": "HTTP1",
        "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
    },
    "id": "tg-0eaa4b9ab4EXAMPLE",
    "name": "my-lattice-target-group-ip",
    "status": "CREATE_IN_PROGRESS",
    "type": "IP"
}
```
**範例 3：建立類型為 LAMBDA 的目標群組**  
下列 `create-target-group` 範例會建立具有指定名稱、類型和組態的目標群組。  

```
aws vpc-lattice create-target-group \
    --name my-lattice-target-group-lambda \
    --type LAMBDA
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE",
    "id": "tg-0eaa4b9ab4EXAMPLE",
    "name": "my-lattice-target-group-lambda",
    "status": "CREATE_IN_PROGRESS",
    "type": "LAMBDA"
}
```
**範例 4：建立類型為 ALB 的目標群組**  
下列 `create-target-group` 範例會建立具有指定名稱、類型和組態的目標群組。  

```
aws vpc-lattice create-target-group \
    --name my-lattice-target-group-alb \
    --type ALB \
    --config file://tg-config.json
```
`tg-config.json` 的內容：  

```
{
    "port": 443,
    "protocol": "HTTPS",
    "protocolVersion": "HTTP1",
    "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
}
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE",
    "config": {
        "port": 443,
        "protocol": "HTTPS",
        "protocolVersion": "HTTP1",
        "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
    },
    "id": "tg-0eaa4b9ab4EXAMPLE",
    "name": "my-lattice-target-group-alb",
    "status": "CREATE_IN_PROGRESS",
    "type": "ALB"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[目標群組](https://docs.aws.amazon.com/vpc-lattice/latest/ug/target-groups.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateTargetGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/create-target-group.html)。

### `delete-auth-policy`
<a name="vpc-lattice_DeleteAuthPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-auth-policy`。

**AWS CLI**  
**刪除驗證政策**  
以下 `delete-auth-policy` 範例會刪除所指定服務的驗證政策。  

```
aws vpc-lattice delete-auth-policy \
    --resource-identifier svc-0285b53b2eEXAMPLE
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[驗證政策](https://docs.aws.amazon.com/vpc-lattice/latest/ug/auth-policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteAuthPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-auth-policy.html)。

### `delete-listener`
<a name="vpc-lattice_DeleteListener_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-listener`。

**AWS CLI**  
**刪除接聽程式**  
以下 `delete-listener` 範例會刪除指定的接聽程式。  

```
aws vpc-lattice delete-listener \
    --listener-identifier listener-07cc7fb0abEXAMPLE \
    --service-identifier svc-0285b53b2eEXAMPLE
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[接聽程式](https://docs.aws.amazon.com/vpc-lattice/latest/ug/listeners.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteListener](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-listener.html)。

### `delete-resource-configuration`
<a name="vpc-lattice_DeleteResourceConfiguration_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-resource-configuration`。

**AWS CLI**  
**刪除資源組態**  
下列 `delete-resource-configuration` 範例會刪除指定的資源組態。  

```
aws vpc-lattice delete-resource-configuration \
    --resource-configuration-identifier rcfg-07129f3acded87625
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的資源閘道](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-configuration.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteResourceConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-resource-configuration.html)。

### `delete-resource-gateway`
<a name="vpc-lattice_DeleteResourceGateway_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-resource-gateway`。

**AWS CLI**  
**刪除資源閘道**  
下列 `delete-resource-gateway` 範例會刪除指定的資源閘道。  

```
aws vpc-lattice delete-resource-gateway \
    --resource-gateway-identifier rgw-0bba03f3d56060135
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourcegateway/rgw-0bba03f3d56060135",
    "id": "rgw-0bba03f3d56060135",
    "name": "my-resource-gateway",
    "status": "DELETE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的資源閘道](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-gateway.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteResourceGateway](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-resource-gateway.html)。

### `delete-service-network-service-association`
<a name="vpc-lattice_DeleteServiceNetworkServiceAssociation_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-service-network-service-association`。

**AWS CLI**  
**刪除服務關聯**  
下列 `delete-service-network-service-association` 範例會取消所指定服務關聯的關聯。  

```
aws vpc-lattice delete-service-network-service-association \
    --service-network-service-association-identifier snsa-031fabb4d8EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkserviceassociation/snsa-031fabb4d8EXAMPLE",
    "id": "snsa-031fabb4d8EXAMPLE",
    "status": "DELETE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理服務關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-service-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteServiceNetworkServiceAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-service-network-service-association.html)。

### `delete-service-network-vpc-association`
<a name="vpc-lattice_DeleteServiceNetworkVpcAssociation_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-service-network-vpc-association`。

**AWS CLI**  
**刪除 VPC 關聯**  
下列 `delete-service-network-vpc-association` 範例會取消所指定 VPC 關聯的關聯。  

```
aws vpc-lattice delete-service-network-vpc-association \
    --service-network-vpc-association-identifier snva-0821fc8631EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkvpcassociation/snva-0821fc8631EXAMPLE",
    "id": "snva-0821fc8631EXAMPLE",
    "status": "DELETE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理 VPC 關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-vpc-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteServiceNetworkVpcAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-service-network-vpc-association.html)。

### `delete-service-network`
<a name="vpc-lattice_DeleteServiceNetwork_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-service-network`。

**AWS CLI**  
**刪除服務網路**  
以下 `delete-service-network` 範例會刪除指定的服務網路。  

```
aws vpc-lattice delete-service-network \
    --service-network-identifier sn-080ec7dc93EXAMPLE
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[服務網路](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-networks.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteServiceNetwork](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-service-network.html)。

### `delete-service`
<a name="vpc-lattice_DeleteService_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-service`。

**AWS CLI**  
**刪除服務**  
下列 `delete-service` 範例會刪除指定的服務。  

```
aws vpc-lattice delete-service \
    --service-identifier svc-0285b53b2eEXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-west-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "id": "svc-0285b53b2eEXAMPLE",
    "name": "my-lattice-service",
    "status": "DELETE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的服務](https://docs.aws.amazon.com/vpc-lattice/latest/ug/services.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteService](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-service.html)。

### `delete-target-group`
<a name="vpc-lattice_DeleteTargetGroup_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-target-group`。

**AWS CLI**  
**刪除目標群組**  
以下 `delete-target-group` 範例會刪除指定的目標群組。  

```
aws vpc-lattice delete-target-group \
    --target-group-identifier tg-0eaa4b9ab4EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE",
    "id": "tg-0eaa4b9ab4EXAMPLE",
    "status": "DELETE_IN_PROGRESS"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[目標群組](https://docs.aws.amazon.com/vpc-lattice/latest/ug/target-groups.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteTargetGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/delete-target-group.html)。

### `deregister-targets`
<a name="vpc-lattice_DeregisterTargets_cli_topic"></a>

以下程式碼範例顯示如何使用 `deregister-targets`。

**AWS CLI**  
**取消註冊目標**  
下列 `deregister-targets` 範例會從指定的目標群組中取消註冊指定的目標。  

```
aws vpc-lattice deregister-targets \
    --targets i-07dd579bc5EXAMPLE \
    --target-group-identifier tg-0eaa4b9ab4EXAMPLE
```
輸出：  

```
{
    "successful": [
        {
            "id": "i-07dd579bc5EXAMPLE",
            "port": 443
        }
    ],
    "unsuccessful": []
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[註冊目標](https://docs.aws.amazon.com/vpc-lattice/latest/ug/register-targets.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeregisterTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/deregister-targets.html)。

### `get-auth-policy`
<a name="vpc-lattice_GetAuthPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-auth-policy`。

**AWS CLI**  
**取得驗證政策的相關資訊**  
下列 `get-auth-policy` 範例會取得指定服務其驗證政策的相關資訊。  

```
aws vpc-lattice get-auth-policy \
    --resource-identifier svc-0285b53b2eEXAMPLE
```
輸出：  

```
{
    "createdAt": "2023-06-07T03:51:20.266Z",
    "lastUpdatedAt": "2023-06-07T04:39:27.082Z",
    "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:role/my-clients\"},\"Action\":\"vpc-lattice-svcs:Invoke\",\"Resource\":\"arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE\"}]}",
    "state": "Active"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[驗證政策](https://docs.aws.amazon.com/vpc-lattice/latest/ug/auth-policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetAuthPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-auth-policy.html)。

### `get-listener`
<a name="vpc-lattice_GetListener_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-listener`。

**AWS CLI**  
**取得服務接聽程式的相關資訊**  
下列 `get-listener` 範例會取得指定服務其指定接聽程式的相關資訊。  

```
aws vpc-lattice get-listener \
    --listener-identifier listener-0ccf55918cEXAMPLE \
    --service-identifier svc-0285b53b2eEXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE/listener/listener-0ccf55918cEXAMPLE",
    "createdAt": "2023-05-07T05:08:45.192Z",
    "defaultAction": {
        "forward": {
            "targetGroups": [
                {
                    "targetGroupIdentifier": "tg-0ff213abb6EXAMPLE",
                    "weight": 1
                }
            ]
        }
    },
    "id": "listener-0ccf55918cEXAMPLE",
    "lastUpdatedAt": "2023-05-07T05:08:45.192Z",
    "name": "http-80",
    "port": 80,
    "protocol": "HTTP",
    "serviceArn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "serviceId": "svc-0285b53b2eEXAMPLE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[定義路由](https://docs.aws.amazon.com/vpc-lattice/latest/ug/services.html#define-routing)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetListener](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-listener.html)。

### `get-resource-configuration`
<a name="vpc-lattice_GetResourceConfiguration_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-resource-configuration`。

**AWS CLI**  
**取得資源組態的相關資訊**  
下列 `get-resource-configuration` 範例會取得指定資源組態的相關資訊。  

```
aws vpc-lattice get-resource-configuration \
    --resource-configuration-identifier rcfg-07129f3acded87625
```
輸出：  

```
{
    "allowAssociationToShareableServiceNetwork": true,
    "amazonManaged": false,
    "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourceconfiguration/rcfg-07129f3acded87625",
    "createdAt": "2025-02-01T00:57:35.871000+00:00",
    "id": "rcfg-07129f3acded87625",
    "lastUpdatedAt": "2025-02-01T00:57:46.874000+00:00",
    "name": "my-resource-config",
    "portRanges": [
        "1-65535"
    ],
    "protocol": "TCP",
    "resourceConfigurationDefinition": {
        "ipResource": {
            "ipAddress": "10.0.14.85"
        }
    },
    "resourceGatewayId": "rgw-0bba03f3d56060135",
    "status": "ACTIVE",
    "type": "SINGLE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的資源閘道](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-configuration.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetResourceConfiguration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-resource-configuration.html)。

### `get-resource-gateway`
<a name="vpc-lattice_GetResourceGateway_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-resource-gateway`。

**AWS CLI**  
**取得資源閘道的相關資訊**  
下列 `get-resource-gateway` 範例會取得指定資源閘道的相關資訊。  

```
aws vpc-lattice get-resource-gateway \
    --resource-gateway-identifier rgw-0bba03f3d56060135
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourcegateway/rgw-0bba03f3d56060135",
    "createdAt": "2025-02-01T00:57:33.241000+00:00",
    "id": "rgw-0bba03f3d56060135",
    "ipAddressType": "IPV4",
    "lastUpdatedAt": "2025-02-01T00:57:44.351000+00:00",
    "name": "my-resource-gateway",
    "securityGroupIds": [
        "sg-087ffd596c5fe962c"
    ],
    "status": "ACTIVE",
    "subnetIds": [
        "subnet-08e8943905b63a683"
    ],
    "vpcId": "vpc-0bf4c2739bc05a694"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的資源閘道](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-gateway.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetResourceGateway](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-resource-gateway.html)。

### `get-service-network-service-association`
<a name="vpc-lattice_GetServiceNetworkServiceAssociation_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-service-network-service-association`。

**AWS CLI**  
**取得服務關聯的相關資訊**  
下列 `get-service-network-service-association` 範例會取得指定服務關聯的相關資訊。  

```
aws vpc-lattice get-service-network-service-association \
    --service-network-service-association-identifier snsa-031fabb4d8EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkserviceassociation/snsa-031fabb4d8EXAMPLE",
    "createdAt": "2023-05-05T21:48:16.076Z",
    "createdBy": "123456789012",
    "dnsEntry": {
        "domainName": "my-lattice-service-0285b53b2eEXAMPLE.7d67968.vpc-lattice-svcs.us-east-2.on.aws",
        "hostedZoneId": "Z09127221KTH2CEXAMPLE"
    },
    "id": "snsa-031fabb4d8EXAMPLE",
    "serviceArn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "serviceId": "svc-0285b53b2eEXAMPLE",
    "serviceName": "my-lattice-service",
    "serviceNetworkArn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-080ec7dc93EXAMPLE",
    "serviceNetworkId": "sn-080ec7dc93EXAMPLE",
    "serviceNetworkName": "my-service-network",
    "status": "ACTIVE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理服務關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-service-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetServiceNetworkServiceAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-service-network-service-association.html)。

### `get-service-network-vpc-association`
<a name="vpc-lattice_GetServiceNetworkVpcAssociation_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-service-network-vpc-association`。

**AWS CLI**  
**取得 VPC 關聯的相關資訊**  
下列 `get-service-network-vpc-association` 範例取得指定 VPC 關聯的相關資訊。  

```
aws vpc-lattice get-service-network-vpc-association \
    --service-network-vpc-association-identifier snva-0821fc8631EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkvpcassociation/snva-0821fc8631EXAMPLE",
    "createdAt": "2023-06-06T23:41:08.421Z",
    "createdBy": "123456789012",
    "id": "snva-0c5dcb60d6EXAMPLE",
    "lastUpdatedAt": "2023-06-06T23:41:08.421Z",
    "securityGroupIds": [
        "sg-0aee16bc6cEXAMPLE"
    ],
    "serviceNetworkArn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-080ec7dc93EXAMPLE",
    "serviceNetworkId": "sn-080ec7dc93EXAMPLE",
    "serviceNetworkName": "my-service-network",
    "status": "ACTIVE",
    "vpcId": "vpc-0a1b2c3d4eEXAMPLE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理 VPC 關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-vpc-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetServiceNetworkVpcAssociation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-service-network-vpc-association.html)。

### `get-service-network`
<a name="vpc-lattice_GetServiceNetwork_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-service-network`。

**AWS CLI**  
**取得服務網路的相關資訊**  
下列 `get-service-network` 範例會取得指定服務網路的相關資訊。  

```
aws vpc-lattice get-service-network \
    --service-network-identifier sn-080ec7dc93EXAMPLE
```
輸出：  

```
{
   "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-080ec7dc93EXAMPLE",
   "authType": "AWS_IAM",
   "createdAt": "2023-05-05T15:26:08.417Z",
   "id": "sn-080ec7dc93EXAMPLE",
   "lastUpdatedAt": "2023-05-05T15:26:08.417Z",
   "name": "my-service-network",
   "numberOfAssociatedServices": 2,
   "numberOfAssociatedVPCs": 3
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[服務網路](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-networks.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetServiceNetwork](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-service-network.html)。

### `get-service`
<a name="vpc-lattice_GetService_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-service`。

**AWS CLI**  
**取得服務的相關資訊**  
下列 `get-service` 範例取得指定服務的相關資訊。  

```
aws vpc-lattice get-service \
    --service-identifier svc-0285b53b2eEXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "authType": "AWS_IAM",
    "createdAt": "2023-05-05T21:35:29.339Z",
    "dnsEntry": {
        "domainName": "my-lattice-service-0285b53b2eEXAMPLE.7d67968.vpc-lattice-svcs.us-east-2.on.aws",
        "hostedZoneId": "Z09127221KTH2CFUOHIZH"
    },
    "id": "svc-0285b53b2eEXAMPLE",
    "lastUpdatedAt": "2023-05-05T21:35:29.339Z",
    "name": "my-lattice-service",
    "status": "ACTIVE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[服務](https://docs.aws.amazon.com/vpc-lattice/latest/ug/services.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetService](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-service.html)。

### `get-target-group`
<a name="vpc-lattice_GetTargetGroup_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-target-group`。

**AWS CLI**  
**取得目標群組的相關資訊**  
下列 `get-target-group` 範例會取得指定目標群組的相關資訊，其目標類型為 `INSTANCE`。  

```
aws vpc-lattice get-target-group \
    --target-group-identifier tg-0eaa4b9ab4EXAMPLE
```
輸出：  

```
{
    "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE",
    "config": {
        "healthCheck": {
            "enabled": true,
            "healthCheckIntervalSeconds": 30,
            "healthCheckTimeoutSeconds": 5,
            "healthyThresholdCount": 5,
            "matcher": {
                "httpCode": "200"
            },
            "path": "/",
            "protocol": "HTTPS",
            "protocolVersion": "HTTP1",
            "unhealthyThresholdCount": 2
        },
        "port": 443,
        "protocol": "HTTPS",
        "protocolVersion": "HTTP1",
        "vpcIdentifier": "vpc-f1663d9868EXAMPLE"
    },
    "createdAt": "2023-05-06T04:41:04.122Z",
    "id": "tg-0eaa4b9ab4EXAMPLE",
    "lastUpdatedAt": "2023-05-06T04:41:04.122Z",
    "name": "my-target-group",
    "serviceArns": [
        "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE"
    ],
    "status": "ACTIVE",
    "type": "INSTANCE"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[目標群組](https://docs.aws.amazon.com/vpc-lattice/latest/ug/target-groups.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetTargetGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/get-target-group.html)。

### `list-listeners`
<a name="vpc-lattice_ListListeners_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-listeners`。

**AWS CLI**  
**列出服務接聽程式**  
下列 `list-listeners` 範例會列出指定服務的接聽程式。  

```
aws vpc-lattice list-listeners \
    --service-identifier svc-0285b53b2eEXAMPLE
```
輸出：  

```
{
    "items": [
        {
            "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE/listener/listener-0ccf55918cEXAMPLE",
            "createdAt": "2023-05-07T05:08:45.192Z",
            "id": "listener-0ccf55918cEXAMPLE",
            "lastUpdatedAt": "2023-05-07T05:08:45.192Z",
            "name": "http-80",
            "port": 80,
            "protocol": "HTTP"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[定義路由](https://docs.aws.amazon.com/vpc-lattice/latest/ug/services.html#define-routing)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListListeners](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-listeners.html)。

### `list-resource-configurations`
<a name="vpc-lattice_ListResourceConfigurations_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-resource-configurations`。

**AWS CLI**  
**列出您的資源組態**  
下列 `list-resource-configurations` 範例會列出您的資源組態。  

```
aws vpc-lattice list-resource-configurations
```
輸出：  

```
{
    "items": [
        {
            "amazonManaged": false,
            "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourceconfiguration/rcfg-07129f3acded87625",
            "createdAt": "2025-02-01T00:57:35.871000+00:00",
            "id": "rcfg-07129f3acded87625",
            "lastUpdatedAt": "2025-02-01T00:57:46.874000+00:00",
            "name": "my-resource-config",
            "resourceGatewayId": "rgw-0bba03f3d56060135",
            "status": "ACTIVE",
            "type": "SINGLE"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[資源組態](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-configuration.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListResourceConfigurations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-resource-configurations.html)。

### `list-resource-endpoint-associations`
<a name="vpc-lattice_ListResourceEndpointAssociations_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-resource-endpoint-associations`。

**AWS CLI**  
**列出 VPC 端點關聯**  
下列 `list-resource-endpoint-associations` 範例會列出與指定資源組態相關聯的 VPC 端點。  

```
aws vpc-lattice list-resource-endpoint-associations \
    --resource-configuration-identifier rcfg-07129f3acded87625
```
輸出：  

```
{
    "items": [
        {
            "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourceendpointassociation/rea-0956a7435baf89326",
            "createdAt": "2025-02-01T00:57:38.998000+00:00",
            "id": "rea-0956a7435baf89326",
            "resourceConfigurationArn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourceconfiguration/rcfg-07129f3acded87625",
            "resourceConfigurationId": "rcfg-07129f3acded87625",
            "vpcEndpointId": "vpce-019b90d6f16d4f958",
            "vpcEndpointOwner": "123456789012"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理 VPC Lattice 資源組態的關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-configuration-associations.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListResourceEndpointAssociations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-resource-endpoint-associations.html)。

### `list-resource-gateways`
<a name="vpc-lattice_ListResourceGateways_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-resource-gateways`。

**AWS CLI**  
**列出您的資源閘道**  
下列 `list-resource-gateways` 範例會列出您的資源閘道。  

```
aws vpc-lattice list-resource-gateways
```
輸出：  

```
{
    "items": [
        {
            "arn": "arn:aws:vpc-lattice:us-east-1:123456789012:resourcegateway/rgw-0bba03f3d56060135",
            "createdAt": "2025-02-01T00:57:33.241000+00:00",
            "id": "rgw-0bba03f3d56060135",
            "ipAddressType": "IPV4",
            "lastUpdatedAt": "2025-02-01T00:57:44.351000+00:00",
            "name": "my-resource-gateway",
            "seurityGroupIds": [
                "sg-087ffd596c5fe962c"
            ],
            "status": "ACTIVE",
            "subnetIds": [
                "subnet-08e8943905b63a683"
            ],
            "vpcIdentifier": "vpc-0bf4c2739bc05a694"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的 [VPC Lattice 中的資源閘道](https://docs.aws.amazon.com/vpc-lattice/latest/ug/resource-gateway.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListResourceGateways](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-resource-gateways.html)。

### `list-service-network-service-associations`
<a name="vpc-lattice_ListServiceNetworkServiceAssociations_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-service-network-service-associations`。

**AWS CLI**  
**列出服務關聯**  
下列 `list-service-network-service-associations` 範例會列出指定服務網路的服務關聯。`--query` 選項會將輸出範圍限制為服務關聯的 ID。  

```
aws vpc-lattice list-service-network-service-associations \
    --service-network-identifier sn-080ec7dc93EXAMPLE \
    --query items[*].id
```
輸出：  

```
[
    "snsa-031fabb4d8EXAMPLE",
    "snsa-0e16955a8cEXAMPLE"
]
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理服務關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-service-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListServiceNetworkServiceAssociations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-service-network-service-associations.html)。

### `list-service-network-vpc-associations`
<a name="vpc-lattice_ListServiceNetworkVpcAssociations_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-service-network-vpc-associations`。

**AWS CLI**  
**列出 VPC 關聯**  
下列 `list-service-network-vpc-associations` 範例會列出指定服務網路的 VPC 關聯。`--query` 選項會將輸出範圍限制為 VPC 關聯的 ID。  

```
aws vpc-lattice list-service-network-vpc-associations \
    --service-network-identifier sn-080ec7dc93EXAMPLE \
    --query items[*].id
```
輸出：  

```
[
    "snva-0821fc8631EXAMPLE",
    "snva-0c5dcb60d6EXAMPLE"
]
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理 VPC 關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html#service-network-vpc-associations)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListServiceNetworkVpcAssociations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-service-network-vpc-associations.html)。

### `list-service-network-vpc-endpoint-associations`
<a name="vpc-lattice_ListServiceNetworkVpcEndpointAssociations_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-service-network-vpc-endpoint-associations`。

**AWS CLI**  
**列出 VPC 端點關聯**  
下列 `list-service-network-vpc-endpoint-associations` 範例會列出與指定服務網路關聯的 VPC 端點。  

```
aws vpc-lattice list-service-network-vpc-endpoint-associations \
    --service-network-identifier sn-0808d1748faee0c1e
```
輸出：  

```
{
    "items": [
        {
            "createdAt": "2025-02-01T01:21:36.667000+00:00",
            "serviceNetworkArn": "arn:aws:vpc-lattice:us-east-1:123456789012:servicenetwork/sn-0808d1748faee0c1e",
            "state": "ACTIVE",
            "vpcEndpointId": "vpce-0cc199f605eaeace7",
            "vpcEndpointOwnerId": "123456789012"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[管理 VPC Lattice 服務網路的關聯](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-network-associations.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListServiceNetworkVpcEndpointAssociations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-service-network-vpc-endpoint-associations.html)。

### `list-service-networks`
<a name="vpc-lattice_ListServiceNetworks_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-service-networks`。

**AWS CLI**  
**列出您的服務網路**  
下列 `list-service-networks` 範例會列出由呼叫帳戶擁有或共用的服務網路。`--query` 選項會將結果範圍限制為服務網路的 Amazon Resource Name (ARN)。  

```
aws vpc-lattice list-service-networks \
    --query items[*].arn
```
輸出：  

```
[
    "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-080ec7dc93EXAMPLE",
    "arn:aws:vpc-lattice:us-east-2:111122223333:servicenetwork/sn-0ec4d436cfEXAMPLE"
]
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[服務網路](https://docs.aws.amazon.com/vpc-lattice/latest/ug/service-networks.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListServiceNetworks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-service-networks.html)。

### `list-services`
<a name="vpc-lattice_ListServices_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-services`。

**AWS CLI**  
**列出您的服務**  
下列`list-services`範例列出呼叫帳戶所擁有或共用的服務。`--query` 選項會將結果範圍限制為服務的 Amazon Resource Name (ARN)。  

```
aws vpc-lattice list-services \
    --query items[*].arn
```
輸出：  

```
[
    "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE",
    "arn:aws:vpc-lattice:us-east-2:111122223333:service/svc-0b8ac96550EXAMPLE"
]
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[服務](https://docs.aws.amazon.com/vpc-lattice/latest/ug/services.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListServices](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-services.html)。

### `list-target-groups`
<a name="vpc-lattice_ListTargetGroups_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-target-groups`。

**AWS CLI**  
**列出您的目標群組**  
下列 `list-target-groups` 範例會列出目標類型為 `LAMBDA` 的目標群組。  

```
aws vpc-lattice list-target-groups \
    --target-group-type LAMBDA
```
輸出：  

```
{
    "items": [
        {
            "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-045c1b7d9dEXAMPLE",
            "createdAt": "2023-05-06T05:22:16.637Z",
            "id": "tg-045c1b7d9dEXAMPLE",
            "lastUpdatedAt": "2023-05-06T05:22:16.637Z",
            "name": "my-target-group-lam",
            "serviceArns": [
                "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE"
            ],
            "status": "ACTIVE",
            "type": "LAMBDA"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[目標群組](https://docs.aws.amazon.com/vpc-lattice/latest/ug/target-groups.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTargetGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-target-groups.html)。

### `list-targets`
<a name="vpc-lattice_ListTargets_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-targets`。

**AWS CLI**  
**列出目標群組的目標**  
下列 `list-targets` 範例顯示指定目標群組的目標。  

```
aws vpc-lattice list-targets \
    --target-group-identifier tg-0eaa4b9ab4EXAMPLE
```
輸出：  

```
{
    "items": [
        {
            "id": "i-07dd579bc5EXAMPLE",
            "port": 443,
            "status": "HEALTHY"
        },
        {
            "id": "i-047b3c9078EXAMPLE",
            "port": 443,
            "reasonCode": "HealthCheckFailed",
            "status": "UNHEALTHY"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[目標群組](https://docs.aws.amazon.com/vpc-lattice/latest/ug/target-groups.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/list-targets.html)。

### `put-auth-policy`
<a name="vpc-lattice_PutAuthPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `put-auth-policy`。

**AWS CLI**  
**為服務建立驗證政策**  
下列 `put-auth-policy` 範例會授予存取權以存取來自使用指定 IAM 角色之任何已驗證主體的請求。資源是政策所連接服務的 ARN。  

```
aws vpc-lattice put-auth-policy \
    --resource-identifier svc-0285b53b2eEXAMPLE \
    --policy file://auth-policy.json
```
`auth-policy.json` 的內容：  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::123456789012:role/my-clients"
            },
            "Action": "vpc-lattice-svcs:Invoke",
            "Resource": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE"
        }
    ]
}
```
輸出：  

```
{
    "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::123456789012:role/my-clients\"},\"Action\":\"vpc-lattice-svcs:Invoke\",\"Resource\":\"arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0285b53b2eEXAMPLE\"}]}",
    "state": "Active"
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[驗證政策](https://docs.aws.amazon.com/vpc-lattice/latest/ug/auth-policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [PutAuthPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/put-auth-policy.html)。

### `register-targets`
<a name="vpc-lattice_RegisterTargets_cli_topic"></a>

以下程式碼範例顯示如何使用 `register-targets`。

**AWS CLI**  
**註冊目標**  
下列 `register-targets` 範例會向指定的目標群組註冊指定的目標。  

```
aws vpc-lattice register-targets \
    --targets id=i-047b3c9078EXAMPLE id=i-07dd579bc5EXAMPLE \
    --target-group-identifier tg-0eaa4b9ab4EXAMPLE
```
輸出：  

```
{
    "successful": [
        {
            "id": "i-07dd579bc5EXAMPLE",
            "port": 443
        }
    ],
    "unsuccessful": [
        {
            "failureCode": "UnsupportedTarget",
            "failureMessage": "Instance targets must be in the same VPC as their target group",
            "id": "i-047b3c9078EXAMPLE",
            "port": 443
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon VPC Lattice 使用者指南》**中的[註冊目標](https://docs.aws.amazon.com/vpc-lattice/latest/ug/register-targets.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [RegisterTargets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/vpc-lattice/register-targets.html)。