本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的 VPC Lattice 範例 AWS CLI
下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 VPC Lattice 來執行動作和實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
主題
動作
以下程式碼範例顯示如何使用 create-listener。
- AWS CLI
-
建立接聽程式
下列
create-listener範例會使用預設規則建立 HTTPS 接聽程式,將流量轉送至指定的 VPC Lattice 目標群組。aws vpc-lattice create-listener \ --namemy-service-listener\ --protocolHTTPS\ --port443\ --service-identifiersvc-0285b53b2eEXAMPLE\ --default-actionfile://listener-config.jsonlistener-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 使用者指南》中的接聽程式。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateListener
。
-
以下程式碼範例顯示如何使用 create-resource-configuration。
- AWS CLI
-
建立資源組態
下列
create-resource-configuration範例會建立指定單一 IPv4 地址的資源組態。aws vpc-lattice create-resource-configuration \ --namemy-resource-config\ --typeSINGLE\ --resource-gateway-identifierrgw-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 資源的資源組態。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateResourceConfiguration
。
-
以下程式碼範例顯示如何使用 create-resource-gateway。
- AWS CLI
-
建立資源閘道
下列
create-resource-gateway範例會為指定的子網路建立資源閘道。aws vpc-lattice create-resource-gateway \ --namemy-resource-gateway\ --vpc-identifiervpc-0bf4c2739bc05a69\ --subnet-idssubnet-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 中的資源閘道。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateResourceGateway
。
-
以下程式碼範例顯示如何使用 create-service-network-service-association。
- AWS CLI
-
建立服務關聯
下列
create-service-network-service-association範例會將指定的服務與指定的服務網路建立關聯。aws vpc-lattice create-service-network-service-association \ --service-identifiersvc-0285b53b2eEXAMPLE\ --service-network-identifiersn-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 使用者指南》中的管理服務關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateServiceNetworkServiceAssociation
。
-
以下程式碼範例顯示如何使用 create-service-network-vpc-association。
- AWS CLI
-
建立 VPC 關聯
下列
create-service-network-vpc-association範例會將指定的 vpc 與指定的服務網路建立關聯。指定的安全群組會控制 VPC 中的哪些資源可以存取服務網路及其服務。aws vpc-lattice create-service-network-vpc-association \ --vpc-identifiervpc-0a1b2c3d4eEXAMPLE\ --service-network-identifiersn-080ec7dc93EXAMPLE\ --security-group-idssg-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 關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateServiceNetworkVpcAssociation
。
-
以下程式碼範例顯示如何使用 create-service-network。
- AWS CLI
-
建立服務網路
下列
create-service-network範例會建立具有指定名稱的服務網路。aws vpc-lattice create-service-network \ --namemy-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 使用者指南》中的服務網路。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateServiceNetwork
。
-
以下程式碼範例顯示如何使用 create-service。
- AWS CLI
-
建立服務
下列
create-service範例會建立具有指定名稱的服務。aws vpc-lattice create-service \ --namemy-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 中的服務。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateService
。
-
以下程式碼範例顯示如何使用 create-target-group。
- AWS CLI
-
範例 1:建立類型為 INSTANCE 的目標群組
下列
create-target-group範例會建立具有指定名稱、類型和組態的目標群組。aws vpc-lattice create-target-group \ --namemy-lattice-target-group-instance\ --typeINSTANCE\ --configfile://tg-config.jsontg-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 \ --namemy-lattice-target-group-ip\ --typeIP\ --configfile://tg-config.jsontg-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 \ --namemy-lattice-target-group-lambda\ --typeLAMBDA輸出:
{ "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 \ --namemy-lattice-target-group-alb\ --typeALB\ --configfile://tg-config.jsontg-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 使用者指南》中的目標群組。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateTargetGroup
。
-
以下程式碼範例顯示如何使用 delete-auth-policy。
- AWS CLI
-
刪除身分驗證政策
下列
delete-auth-policy範例會刪除指定服務的身分驗證政策。aws vpc-lattice delete-auth-policy \ --resource-identifiersvc-0285b53b2eEXAMPLE此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的身分驗證政策。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteAuthPolicy
。
-
以下程式碼範例顯示如何使用 delete-listener。
- AWS CLI
-
刪除接聽程式
下列
delete-listener範例會刪除指定的接聽程式。aws vpc-lattice delete-listener \ --listener-identifierlistener-07cc7fb0abEXAMPLE\ --service-identifiersvc-0285b53b2eEXAMPLE此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的接聽程式。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteListener
。
-
以下程式碼範例顯示如何使用 delete-resource-configuration。
- AWS CLI
-
刪除資源組態
下列
delete-resource-configuration範例會刪除指定的資源組態。aws vpc-lattice delete-resource-configuration \ --resource-configuration-identifierrcfg-07129f3acded87625此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的 VPC Lattice 中的資源閘道。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteResourceConfiguration
。
-
以下程式碼範例顯示如何使用 delete-resource-gateway。
- AWS CLI
-
刪除資源閘道
下列
delete-resource-gateway範例會刪除指定的資源閘道。aws vpc-lattice delete-resource-gateway \ --resource-gateway-identifierrgw-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 中的資源閘道。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteResourceGateway
。
-
以下程式碼範例顯示如何使用 delete-service-network-service-association。
- AWS CLI
-
刪除服務關聯
下列
delete-service-network-service-association範例會取消指定服務關聯的關聯。aws vpc-lattice delete-service-network-service-association \ --service-network-service-association-identifiersnsa-031fabb4d8EXAMPLE輸出:
{ "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkserviceassociation/snsa-031fabb4d8EXAMPLE", "id": "snsa-031fabb4d8EXAMPLE", "status": "DELETE_IN_PROGRESS" }如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的管理服務關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteServiceNetworkServiceAssociation
。
-
以下程式碼範例顯示如何使用 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-identifiersnva-0821fc8631EXAMPLE輸出:
{ "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetworkvpcassociation/snva-0821fc8631EXAMPLE", "id": "snva-0821fc8631EXAMPLE", "status": "DELETE_IN_PROGRESS" }如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的管理 VPC 關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteServiceNetworkVpcAssociation
。
-
以下程式碼範例顯示如何使用 delete-service-network。
- AWS CLI
-
刪除服務網路
下列
delete-service-network範例會刪除指定的服務網路。aws vpc-lattice delete-service-network \ --service-network-identifiersn-080ec7dc93EXAMPLE此命令不會產生輸出。
如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的服務網路。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteServiceNetwork
。
-
以下程式碼範例顯示如何使用 delete-service。
- AWS CLI
-
刪除服務
下列
delete-service範例會刪除指定的服務。aws vpc-lattice delete-service \ --service-identifiersvc-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 中的服務。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteService
。
-
以下程式碼範例顯示如何使用 delete-target-group。
- AWS CLI
-
刪除目標群組
下列
delete-target-group範例會刪除指定的目標群組。aws vpc-lattice delete-target-group \ --target-group-identifiertg-0eaa4b9ab4EXAMPLE輸出:
{ "arn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-0eaa4b9ab4EXAMPLE", "id": "tg-0eaa4b9ab4EXAMPLE", "status": "DELETE_IN_PROGRESS" }如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的目標群組。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteTargetGroup
。
-
以下程式碼範例顯示如何使用 deregister-targets。
- AWS CLI
-
取消註冊目標
下列
deregister-targets範例會從指定的目標群組取消註冊指定的目標。aws vpc-lattice deregister-targets \ --targetsi-07dd579bc5EXAMPLE\ --target-group-identifiertg-0eaa4b9ab4EXAMPLE輸出:
{ "successful": [ { "id": "i-07dd579bc5EXAMPLE", "port": 443 } ], "unsuccessful": [] }如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的註冊目標。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeregisterTargets
。
-
以下程式碼範例顯示如何使用 get-auth-policy。
- AWS CLI
-
取得身分驗證政策的相關資訊
下列
get-auth-policy範例取得指定服務之身分驗證政策的相關資訊。aws vpc-lattice get-auth-policy \ --resource-identifiersvc-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 使用者指南》中的身分驗證政策。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetAuthPolicy
。
-
以下程式碼範例顯示如何使用 get-listener。
- AWS CLI
-
取得服務接聽程式的相關資訊
下列
get-listener範例會取得指定服務之指定接聽程式的相關資訊。aws vpc-lattice get-listener \ --listener-identifierlistener-0ccf55918cEXAMPLE\ --service-identifiersvc-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 使用者指南》中的定義路由。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetListener
。
-
以下程式碼範例顯示如何使用 get-resource-configuration。
- AWS CLI
-
取得資源組態的相關資訊
下列
get-resource-configuration範例會取得指定資源組態的相關資訊。aws vpc-lattice get-resource-configuration \ --resource-configuration-identifierrcfg-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 中的資源閘道。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetResourceConfiguration
。
-
以下程式碼範例顯示如何使用 get-resource-gateway。
- AWS CLI
-
取得資源閘道的相關資訊
下列
get-resource-gateway範例取得指定資源閘道的相關資訊。aws vpc-lattice get-resource-gateway \ --resource-gateway-identifierrgw-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 中的資源閘道。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetResourceGateway
。
-
以下程式碼範例顯示如何使用 get-service-network-service-association。
- AWS CLI
-
取得服務關聯的相關資訊
下列
get-service-network-service-association範例會取得指定服務關聯的相關資訊。aws vpc-lattice get-service-network-service-association \ --service-network-service-association-identifiersnsa-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 使用者指南》中的管理服務關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetServiceNetworkServiceAssociation
。
-
以下程式碼範例顯示如何使用 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-identifiersnva-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 關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetServiceNetworkVpcAssociation
。
-
以下程式碼範例顯示如何使用 get-service-network。
- AWS CLI
-
取得服務網路的相關資訊
下列
get-service-network範例取得指定服務網路的相關資訊。aws vpc-lattice get-service-network \ --service-network-identifiersn-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 使用者指南》中的服務網路。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetServiceNetwork
。
-
以下程式碼範例顯示如何使用 get-service。
- AWS CLI
-
取得服務的相關資訊
下列
get-service範例會取得指定服務的相關資訊。aws vpc-lattice get-service \ --service-identifiersvc-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 使用者指南》中的服務。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetService
。
-
以下程式碼範例顯示如何使用 get-target-group。
- AWS CLI
-
取得目標群組的相關資訊
下列
get-target-group範例取得指定目標群組的相關資訊,其目標類型為INSTANCE。aws vpc-lattice get-target-group \ --target-group-identifiertg-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 使用者指南》中的目標群組。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetTargetGroup
。
-
以下程式碼範例顯示如何使用 list-listeners。
- AWS CLI
-
列出服務接聽程式
下列
list-listeners範例列出指定服務的接聽程式。aws vpc-lattice list-listeners \ --service-identifiersvc-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 使用者指南》中的定義路由。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListListeners
。
-
以下程式碼範例顯示如何使用 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 使用者指南》中的資源組態。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListResourceConfigurations
。
-
以下程式碼範例顯示如何使用 list-resource-endpoint-associations。
- AWS CLI
-
列出 VPC 端點關聯
下列
list-resource-endpoint-associations範例列出與指定資源組態相關聯的 VPC 端點。aws vpc-lattice list-resource-endpoint-associations \ --resource-configuration-identifierrcfg-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 資源組態的關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListResourceEndpointAssociations
。
-
以下程式碼範例顯示如何使用 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 中的資源閘道。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListResourceGateways
。
-
以下程式碼範例顯示如何使用 list-service-network-service-associations。
- AWS CLI
-
列出服務關聯
下列
list-service-network-service-associations範例列出指定服務網路的服務關聯。--query選項會將輸出範圍限制為服務關聯的 IDs。aws vpc-lattice list-service-network-service-associations \ --service-network-identifiersn-080ec7dc93EXAMPLE\ --queryitems[*].id輸出:
[ "snsa-031fabb4d8EXAMPLE", "snsa-0e16955a8cEXAMPLE" ]如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的管理服務關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListServiceNetworkServiceAssociations
。
-
以下程式碼範例顯示如何使用 list-service-network-vpc-associations。
- AWS CLI
-
列出 VPC 關聯
下列
list-service-network-vpc-associations範例列出指定服務網路的 VPC 關聯。--query選項會將輸出範圍限制為 VPC IDs。aws vpc-lattice list-service-network-vpc-associations \ --service-network-identifiersn-080ec7dc93EXAMPLE\ --queryitems[*].id輸出:
[ "snva-0821fc8631EXAMPLE", "snva-0c5dcb60d6EXAMPLE" ]如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的管理 VPC 關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListServiceNetworkVpcAssociations
。
-
以下程式碼範例顯示如何使用 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-identifiersn-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 服務網路的關聯。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListServiceNetworkVpcEndpointAssociations
。
-
以下程式碼範例顯示如何使用 list-service-networks。
- AWS CLI
-
列出您的服務網路
下列
list-service-networks範例列出與呼叫帳戶擁有或共用的服務網路。--query選項會將結果範圍限定為服務網路的 Amazon Resource Name (ARN)。aws vpc-lattice list-service-networks \ --queryitems[*].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 使用者指南》中的服務網路。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListServiceNetworks
。
-
以下程式碼範例顯示如何使用 list-services。
- AWS CLI
-
列出您的 服務
下列
list-services範例列出呼叫帳戶所擁有或共用的 服務。--query選項會將結果範圍限定為服務的 Amazon Resource Name (ARN)。aws vpc-lattice list-services \ --queryitems[*].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 使用者指南》中的服務。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListServices
。
-
以下程式碼範例顯示如何使用 list-target-groups。
- AWS CLI
-
列出您的目標群組
下列
list-target-groups範例列出目標類型為 的目標群組LAMBDA。aws vpc-lattice list-target-groups \ --target-group-typeLAMBDA輸出:
{ "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 使用者指南》中的目標群組。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListTargetGroups
。
-
以下程式碼範例顯示如何使用 list-targets。
- AWS CLI
-
列出目標群組的目標
下列
list-targets範例列出指定目標群組的目標。aws vpc-lattice list-targets \ --target-group-identifiertg-0eaa4b9ab4EXAMPLE輸出:
{ "items": [ { "id": "i-07dd579bc5EXAMPLE", "port": 443, "status": "HEALTHY" }, { "id": "i-047b3c9078EXAMPLE", "port": 443, "reasonCode": "HealthCheckFailed", "status": "UNHEALTHY" } ] }如需詳細資訊,請參閱《Amazon VPC Lattice 使用者指南》中的目標群組。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListTargets
。
-
以下程式碼範例顯示如何使用 put-auth-policy。
- AWS CLI
-
為服務建立身分驗證政策
下列
put-auth-policy範例會授予來自使用指定 IAM 角色之任何已驗證委託人的請求存取權。資源是政策所連接之服務的 ARN。aws vpc-lattice put-auth-policy \ --resource-identifiersvc-0285b53b2eEXAMPLE\ --policyfile://auth-policy.jsonauth-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 使用者指南》中的身分驗證政策。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 PutAuthPolicy
。
-
以下程式碼範例顯示如何使用 register-targets。
- AWS CLI
-
註冊目標
下列
register-targets範例會向指定的目標群組註冊指定的目標。aws vpc-lattice register-targets \ --targetsid=i-047b3c9078EXAMPLEid=i-07dd579bc5EXAMPLE\ --target-group-identifiertg-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 使用者指南》中的註冊目標。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 RegisterTargets
。
-