文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 的授權管理員範例 AWS CLI
下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 License Manager 來執行動作和實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
主題
動作
以下程式碼範例顯示如何使用 create-license-configuration。
- AWS CLI
-
範例 1:建立授權組態
下列
create-license-configuration範例會建立硬性限制為 10 個核心的授權組態。aws license-manager create-license-configuration --namemy-license-configuration\ --license-counting-typeCore\ --license-count10\ --license-count-hard-limit輸出:
{ "LicenseConfigurationArn": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba41EXAMPLE1111" }範例 2:建立授權組態
下列
create-license-configuration範例會建立軟性限制為 100 個 vCPUs的授權組態。它使用規則來啟用 vCPU 最佳化。aws license-manager create-license-configuration --namemy-license-configuration--license-counting-typevCPU\ --license-count100\ --license-rules"#honorVcpuOptimization=true"輸出:
{ "LicenseConfigurationArn": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba41EXAMPLE2222" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 CreateLicenseConfiguration
。
-
以下程式碼範例顯示如何使用 delete-license-configuration。
- AWS CLI
-
刪除授權組態
下列
delete-license-configuration範例會刪除指定的授權組態。aws license-manager delete-license-configuration \ --license-configuration-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE此命令不會產生輸出。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 DeleteLicenseConfiguration
。
-
以下程式碼範例顯示如何使用 get-license-configuration。
- AWS CLI
-
取得授權組態資訊
下列
get-license-configuration範例顯示指定授權組態的詳細資訊。aws license-manager get-license-configuration \ --license-configuration-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE輸出:
{ "LicenseConfigurationId": "lic-38b658717b87478aaa7c00883EXAMPLE", "LicenseConfigurationArn": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE", "Name": "my-license-configuration", "LicenseCountingType": "vCPU", "LicenseRules": [], "LicenseCountHardLimit": false, "ConsumedLicenses": 0, "Status": "AVAILABLE", "OwnerAccountId": "123456789012", "ConsumedLicenseSummaryList": [ { "ResourceType": "EC2_INSTANCE", "ConsumedLicenses": 0 }, { "ResourceType": "EC2_HOST", "ConsumedLicenses": 0 }, { "ResourceType": "SYSTEMS_MANAGER_MANAGED_INSTANCE", "ConsumedLicenses": 0 } ], "ManagedResourceSummaryList": [ { "ResourceType": "EC2_INSTANCE", "AssociationCount": 0 }, { "ResourceType": "EC2_HOST", "AssociationCount": 0 }, { "ResourceType": "EC2_AMI", "AssociationCount": 2 }, { "ResourceType": "SYSTEMS_MANAGER_MANAGED_INSTANCE", "AssociationCount": 0 } ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetLicenseConfiguration
。
-
以下程式碼範例顯示如何使用 get-service-settings。
- AWS CLI
-
取得 License Manager 設定
下列
get-service-settings範例顯示目前區域中 License Manager 的服務設定。aws license-manager get-service-settings下列顯示停用跨帳戶資源探索時的輸出範例。
{ "OrganizationConfiguration": { "EnableIntegration": false }, "EnableCrossAccountsDiscovery": false }下列顯示啟用跨帳戶資源探索時的輸出範例。
{ "S3BucketArn": "arn:aws:s3:::aws-license-manager-service-c22d6279-35c4-47c4-bb", "OrganizationConfiguration": { "EnableIntegration": true }, "EnableCrossAccountsDiscovery": true }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 GetServiceSettings
。
-
以下程式碼範例顯示如何使用 list-associations-for-license-configuration。
- AWS CLI
-
取得授權組態的關聯
下列
list-associations-for-license-configuration範例顯示指定授權組態之關聯的詳細資訊。aws license-manager list-associations-for-license-configuration \ --license-configuration-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE輸出:
{ "LicenseConfigurationAssociations": [ { "ResourceArn": "arn:aws:ec2:us-west-2::image/ami-1234567890abcdef0", "ResourceType": "EC2_AMI", "ResourceOwnerId": "123456789012", "AssociationTime": 1568825118.617 }, { "ResourceArn": "arn:aws:ec2:us-west-2::image/ami-0abcdef1234567890", "ResourceType": "EC2_AMI", "ResourceOwnerId": "123456789012", "AssociationTime": 1568825118.946 } ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListAssociationsForLicenseConfiguration
。
-
以下程式碼範例顯示如何使用 list-license-configurations。
- AWS CLI
-
範例 1:列出所有授權組態
下列
list-license-configurations範例列出所有授權組態。aws license-manager list-license-configurations輸出:
{ "LicenseConfigurations": [ { "LicenseConfigurationId": "lic-6eb6586f508a786a2ba4f56c1EXAMPLE", "LicenseConfigurationArn": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE", "Name": "my-license-configuration", "LicenseCountingType": "Core", "LicenseRules": [], "LicenseCount": 10, "LicenseCountHardLimit": true, "ConsumedLicenses": 0, "Status": "AVAILABLE", "OwnerAccountId": "123456789012", "ConsumedLicenseSummaryList": [ { "ResourceType": "EC2_INSTANCE", "ConsumedLicenses": 0 }, { "ResourceType": "EC2_HOST", "ConsumedLicenses": 0 }, { "ResourceType": "SYSTEMS_MANAGER_MANAGED_INSTANCE", "ConsumedLicenses": 0 } ], "ManagedResourceSummaryList": [ { "ResourceType": "EC2_INSTANCE", "AssociationCount": 0 }, { "ResourceType": "EC2_HOST", "AssociationCount": 0 }, { "ResourceType": "EC2_AMI", "AssociationCount": 0 }, { "ResourceType": "SYSTEMS_MANAGER_MANAGED_INSTANCE", "AssociationCount": 0 } ] }, { ... } ] }範例 2:列出特定授權組態
下列
list-license-configurations範例只會列出指定的授權組態。aws license-manager list-license-configurations \ --license-configuration-arnsarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListLicenseConfigurations
。
-
以下程式碼範例顯示如何使用 list-license-specifications-for-resource。
- AWS CLI
-
列出資源的授權組態
下列
list-license-specifications-for-resource範例列出與指定 Amazon Machine Image (AMI) 相關聯的授權組態。aws license-manager list-license-specifications-for-resource \ --resource-arnarn:aws:ec2:us-west-2::image/ami-1234567890abcdef0輸出:
{ "LicenseConfigurationArn": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE" }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListLicenseSpecificationsForResource
。
-
以下程式碼範例顯示如何使用 list-resource-inventory。
- AWS CLI
-
列出資源庫存中的資源
下列
list-resource-inventory範例列出使用 Systems Manager 庫存管理的資源。aws license-manager list-resource-inventory輸出:
{ "ResourceInventoryList": [ { "Platform": "Red Hat Enterprise Linux Server", "ResourceType": "EC2Instance", "PlatformVersion": "7.4", "ResourceArn": "arn:aws:ec2:us-west-2:1234567890129:instance/i-05d3cdfb05bd36376", "ResourceId": "i-05d3cdfb05bd36376", "ResourceOwningAccountId": "1234567890129" }, { "Platform": "Amazon Linux", "ResourceType": "EC2Instance", "PlatformVersion": "2", "ResourceArn": "arn:aws:ec2:us-west-2:1234567890129:instance/i-0b1d036cfd4594808", "ResourceId": "i-0b1d036cfd4594808", "ResourceOwningAccountId": "1234567890129" }, { "Platform": "Microsoft Windows Server 2019 Datacenter", "ResourceType": "EC2Instance", "PlatformVersion": "10.0.17763", "ResourceArn": "arn:aws:ec2:us-west-2:1234567890129:instance/i-0cdb3b54a2a8246ad", "ResourceId": "i-0cdb3b54a2a8246ad", "ResourceOwningAccountId": "1234567890129" } ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListResourceInventory
。
-
以下程式碼範例顯示如何使用 list-tags-for-resource。
- AWS CLI
-
列出授權組態的標籤
下列
list-tags-for-resource範例列出指定授權組態的標籤。aws license-manager list-tags-for-resource \ --resource-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE輸出:
{ "Tags": [ { "Key": "project", "Value": "lima" } ] }-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListTagsForResource
。
-
以下程式碼範例顯示如何使用 list-usage-for-license-configuration。
- AWS CLI
-
列出用於授權組態的授權
下列
list-usage-for-license-configuration範例列出使用指定授權組態之授權的資源相關資訊。例如,如果授權類型是 vCPU,則任何執行個體每個 vCPU 都會耗用一個授權。aws license-manager list-usage-for-license-configuration \ --license-configuration-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE輸出:
{ "LicenseConfigurationUsageList": [ { "ResourceArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-04a636d18e83cfacb", "ResourceType": "EC2_INSTANCE", "ResourceStatus": "running", "ResourceOwnerId": "123456789012", "AssociationTime": 1570892850.519, "ConsumedLicenses": 2 } ] }-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 ListUsageForLicenseConfiguration
。
-
以下程式碼範例顯示如何使用 tag-resource。
- AWS CLI
-
新增標籤授權組態
下列
tag-resource範例會將指定的標籤 (索引鍵名稱和值) 新增至指定的授權組態。aws license-manager tag-resource \ --tagsKey=project,Value=lima\ --resource-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE此命令不會產生輸出。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 TagResource
。
-
以下程式碼範例顯示如何使用 untag-resource。
- AWS CLI
-
從授權組態中移除標籤
下列
untag-resource範例會從指定的授權組態中移除指定的標籤 (金鑰名稱和資源)。aws license-manager untag-resource \ --tag-keysproject\ --resource-arnarn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE此命令不會產生輸出。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 UntagResource
。
-
以下程式碼範例顯示如何使用 update-license-configuration。
- AWS CLI
-
更新授權組態
下列
update-license-configuration範例會更新指定的授權組態,以移除硬性限制。aws license-manager update-license-configuration \ --no-license-count-hard-limit \ --license-configuration-arnarn:aws:license-manager:us-west-2:880185128111:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE此命令不會產生輸出。
下列
update-license-configuration範例會更新指定的授權組態,將其狀態變更為DISABLED。aws license-manager update-license-configuration \ --license-configuration-statusDISABLED--license-configuration-arnarn:aws:license-manager:us-west-2:880185128111:license-configuration:lic-6eb6586f508a786a2ba4f56c1EXAMPLE此命令不會產生輸出。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateLicenseConfiguration
。
-
以下程式碼範例顯示如何使用 update-license-specifications-for-resource。
- AWS CLI
-
更新資源的授權組態
下列
update-license-specifications-for-resource範例會移除一個授權組態並新增另一個授權組態,以取代與指定 Amazon Machine Image (AMI) 相關聯的授權組態。aws license-manager update-license-specifications-for-resource \ --resource-arnarn:aws:ec2:us-west-2::image/ami-1234567890abcdef0\ --remove-license-specificationsLicenseConfigurationArn=arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-38b658717b87478aaa7c00883EXAMPLE\ --add-license-specificationsLicenseConfigurationArn=arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-42b6deb06e5399a980d555927EXAMPLE此命令不會產生輸出。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateLicenseSpecificationsForResource
。
-
以下程式碼範例顯示如何使用 update-service-settings。
- AWS CLI
-
更新 License Manager 設定
下列
update-service-settings範例會啟用目前 AWS 區域中 License Manager 的跨帳戶資源探索。Amazon S3 儲存貯體是 Systems Manager 庫存所需的資源資料同步。aws license-manager update-service-settings \ --organization-configurationEnableIntegration=true\ --enable-cross-accounts-discovery \ --s3-bucket-arnarn:aws:s3:::aws-license-manager-service-abcd1234EXAMPLE此命令不會產生輸出。
-
如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateServiceSettings
。
-