AWS RAM 使用範例 AWS CLI - AWS Command Line Interface

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

AWS RAM 使用範例 AWS CLI

下列程式碼範例說明如何使用 AWS Command Line Interface 與來執行動作及實作常見案例 AWS RAM。

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

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用accept-resource-share-invitation

AWS CLI

接受資源共用邀請

下列accept-resource-share-invitation範例會接受指定的資源共用邀請。受邀帳戶中的主參與者可立即開始使用共用中的資源。

aws ram accept-resource-share-invitation \ --resource-share-invitation-arn arn:aws:ram:us-west-2:111111111111:resource-share-invitation/1e3477be-4a95-46b4-bbe0-c4001EXAMPLE

輸出:

{ "resourceShareInvitation": { "resourceShareInvitationArn": "arn:aws:ram:us-west-2:111111111111:resource-share-invitation/1e3477be-4a95-46b4-bbe0-c4001EXAMPLE", "resourceShareName": "MyLicenseShare", "resourceShareArn": "arn:aws:ram:us-west-2:111111111111:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE", "senderAccountId": "111111111111", "receiverAccountId": "222222222222", "invitationTimestamp": "2021-09-22T15:07:35.620000-07:00", "status": "ACCEPTED" } }

下列程式碼範例會示範如何使用associate-resource-share-permission

AWS CLI

將 RAM 管理權限與資源共用產生關聯

下列associate-resource-share-permission範例會以指定的 Managed 權限取代相關資源類型的現有 Managed 權限。對相關資源類型的所有資源的存取權由新權限控制。

aws ram associate-resource-share-permission \ --permission-arn arn:aws:ram::aws:permission/AWSRAMPermissionGlueDatabaseReadWrite \ --replace \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE

輸出:

{ "returnValue": true }

下列程式碼範例會示範如何使用associate-resource-share

AWS CLI

範例 1:將資源與資源共用產生關聯

下列associate-resource-share範例會將授權組態新增至指定的資源共用。

aws ram associate-resource-share \ --resource-share arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE \ --resource-arns arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-36be0485f5ae379cc74cf8e92EXAMPLE

輸出:

{ "resourceShareAssociations": [ { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE", "associatedEntity": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-36be0485f5ae379cc74cf8e92EXAMPLE", "associationType": "RESOURCE", "status": "ASSOCIATING", "external": false } ] }

範例 2:將主參與者與資源共用關聯

下列associate-resource-share範例會將指定資源共用的存取權授與指定組織單位中的所有帳號。

aws ram associate-resource-share \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE \ --principals arn:aws:organizations::123456789012:ou/o-63bEXAMPLE/ou-46xi-rEXAMPLE

輸出:

{ "resourceShareAssociations": [ { "status": "ASSOCIATING", "associationType": "PRINCIPAL", "associatedEntity": "arn:aws:organizations::123456789012:ou/o-63bEXAMPLE/ou-46xi-rEXAMPLE", "external": false, "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE" } ] }

下列程式碼範例會示範如何使用create-resource-share

AWS CLI

範例 1:建立資源共用

下列create-resource-share範例會建立具有指定名稱的空白資源共用。您必須分別將資源、主參與者和權限新增至共用。

aws ram create-resource-share \ --name MyNewResourceShare

輸出:

{ "resourceShare": { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/4476c27d-8feb-4b21-afe9-7de23EXAMPLE", "name": "MyNewResourceShare", "owningAccountId": "123456789012", "allowExternalPrincipals": true, "status": "ACTIVE", "creationTime": 1634586271.302, "lastUpdatedTime": 1634586271.302 } }

範例 2:建立以 AWS 帳號為主參與者的資源共用

下列create-resource-share範例會建立資源共用,並授予指定 AWS 帳號 (222222222222) 的存取權。如果指定的主參與者不屬於同一 AWS 組織,則會傳送邀請,且必須接受邀請,才能授與存取權。

aws ram create-resource-share \ --name MyNewResourceShare \ --principals 222222222222

範例 3:建立僅限於您 AWS 組織的資源共用

下列create-resource-share範例會建立僅限於您帳戶所屬之「 AWS 組織」中帳號的資源共用,並將指定的 OU 新增為主參與者。該 OU 中的所有帳號都可以使用資源共用中的資源。

aws ram create-resource-share \ --name MyNewResourceShare \ --no-allow-external-principals \ --principals arn:aws:organizations::123456789012:ou/o-63bEXAMPLE/ou-46xi-rEXAMPLE

輸出:

{ "resourceShare": { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7be8694e-095c-41ca-9ce8-7be4aEXAMPLE", "name": "MyNewResourceShare", "owningAccountId": "123456789012", "allowExternalPrincipals": false, "status": "ACTIVE", "creationTime": 1634587042.49, "lastUpdatedTime": 1634587042.49 } }

下列程式碼範例會示範如何使用delete-resource-share

AWS CLI

若要刪除資源共用

下列delete-resource-share範例會刪除指定的資源共用。

aws ram delete-resource-share \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE

下面的輸出表示成功:

{ "returnValue": true }

下列程式碼範例會示範如何使用disassociate-resource-share-permission

AWS CLI

若要從資源共用中移除資源類型的 RAM 受管理權限

下列disassociate-resource-share-permission範例會從指定的資源共用中移除 Glue 資料庫的 RAM 管理權限。

aws ram disassociate-resource-share-permission \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE \ --permission-arn arn:aws:ram::aws:permission/AWSRAMPermissionGlueDatabaseReadWrite

輸出:

{ "returnValue": true }

下列程式碼範例會示範如何使用disassociate-resource-share

AWS CLI

若要從資源共用中移除資源

下列disassociate-resource-share範例會從指定的資源共用中移除指定的資源 (在此情況下為 VPC 子網路)。任何具有資源共用存取權的主參與者都無法再對該資源執行作業。

aws ram disassociate-resource-share \ --resource-arns arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0250c25a1fEXAMPLE \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE

輸出:

{ "resourceShareAssociations": [ "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "associatedEntity": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0250c25a1fEXAMPLE", "associationType": "RESOURCE", "status": "DISASSOCIATING", "external": false ] }

下列程式碼範例會示範如何使用enable-sharing-with-aws-organization

AWS CLI

若要啟用跨 Organ AWS izations 的資源共用

下列enable-sharing-with-aws-organization範例可讓您在組織和組織單位之間共用資源。

aws ram enable-sharing-with-aws-organization

以下輸出表示成功。

{ "returnValue": true }

下列程式碼範例會示範如何使用get-permission

AWS CLI

擷取 RAM 管理權限的詳細資料

下列get-permission範例會顯示指定 RAM 受管理權限之預設版本的詳細資料。

aws ram get-permission \ --permission-arn arn:aws:ram::aws:permission/AWSRAMPermissionGlueTableReadWriteForDatabase

輸出:

{ "permission": { "arn": "arn:aws:ram::aws:permission/AWSRAMPermissionGlueTableReadWriteForDatabase", "version": "2", "defaultVersion": true, "name": "AWSRAMPermissionGlueTableReadWriteForDatabase", "resourceType": "glue:Database", "permission": "{\"Effect\":\"Allow\",\"Action\":[\"glue:GetTable\", \"glue:UpdateTable\", \"glue:DeleteTable\", \"glue:BatchDeleteTable\", \"glue:BatchDeleteTableVersion\", \"glue:GetTableVersion\", \"glue:GetTableVersions\", \"glue:GetPartition\", \"glue:GetPartitions\", \"glue:BatchGetPartition\", \"glue:BatchCreatePartition\", \"glue:CreatePartition\", \"glue:UpdatePartition\", \"glue:BatchDeletePartition\", \"glue:DeletePartition\", \"glue:GetTables\", \"glue:SearchTables\"]}", "creationTime": 1624912434.431, "lastUpdatedTime": 1624912434.431, "isResourceTypeDefault": false } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetPermission中的。

下列程式碼範例會示範如何使用get-resource-policies

AWS CLI

若要取得資源的原則

下列get-resource-policies範例顯示與資源共用關聯之指定資源的以資源為基礎的權限原則。

aws ram get-resource-policies \ --resource-arns arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0250c25a1fEXAMPLE

輸出:

{ "policies": [ "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"RamStatement1\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[]},\"Action\":[\"ec2:RunInstances\",\"ec2:CreateNetworkInterface\",\"ec2:DescribeSubnets\"],\"Resource\":\"arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0250c25a1fEXAMPLE\"}]}" ] }

下列程式碼範例會示範如何使用get-resource-share-associations

AWS CLI

範例 1:列出所有資源類型的所有資源關聯

下列get-resource-share-associations範例會列出所有資源共用中所有資源型態的資源關聯。

aws ram get-resource-share-associations \ --association-type RESOURCE

輸出:

{ "resourceShareAssociations": [ { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "associatedEntity": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0250c25a1fEXAMPLE", "resourceShareName": "MySubnetShare", "associationType": "RESOURCE", "status": "ASSOCIATED", "creationTime": 1565303590.973, "lastUpdatedTime": 1565303591.695, "external": false }, { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/8167bdfe-4480-4a01-8632-315e0EXAMPLE", "associatedEntity": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-36be0485f5ae379cc74cf8e92EXAMPLE", "resourceShareName": "MyLicenseShare", "associationType": "RESOURCE", "status": "ASSOCIATED", "creationTime": 1632342958.457, "lastUpdatedTime": 1632342958.907, "external": false } ] }

範例 2:若要列出資源共用的主參與者關聯

下列get-resource-share-associations範例僅列出指定資源共用的主參與者關聯。

aws ram get-resource-share-associations \ --resource-share-arns arn:aws:ram:us-west-2:123456789012:resource-share/7be8694e-095c-41ca-9ce8-7be4aEXAMPLE \ --association-type PRINCIPAL

輸出:

{ "resourceShareAssociations": [ { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7be8694e-095c-41ca-9ce8-7be4aEXAMPLE", "resourceShareName": "MyNewResourceShare", "associatedEntity": "arn:aws:organizations::123456789012:ou/o-63bEXAMPLE/ou-46xi-rEXAMPLE", "associationType": "PRINCIPAL", "status": "ASSOCIATED", "creationTime": 1634587042.49, "lastUpdatedTime": 1634587044.291, "external": false } ] }

下列程式碼範例會示範如何使用get-resource-share-invitations

AWS CLI

列出您的資源共用邀請

下列get-resource-share-invitations範例會列出您目前的資源共用邀請。

aws ram get-resource-share-invitations

輸出:

{ "resourceShareInvitations": [ { "resourceShareInvitationArn": "arn:aws:ram:us-west2-1:111111111111:resource-share-invitation/32b639f0-14b8-7e8f-55ea-e6117EXAMPLE", "resourceShareName": "project-resource-share", "resourceShareArn": "arn:aws:ram:us-west-2:111111111111:resource-share/fcb639f0-1449-4744-35bc-a983fEXAMPLE", "senderAccountId": "111111111111", "receiverAccountId": "222222222222", "invitationTimestamp": 1565312166.258, "status": "PENDING" } ] }

下列程式碼範例會示範如何使用get-resource-shares

AWS CLI

範例 1:列出您擁有並與他人共用的資源共用

下列get-resource-shares範例會列出建立並與其他使用者共用的資源共用。

aws ram get-resource-shares \ --resource-owner SELF

輸出:

{ "resourceShares": [ { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/3ab63985-99d9-1cd2-7d24-75e93EXAMPLE", "name": "my-resource-share", "owningAccountId": "123456789012", "allowExternalPrincipals": false, "status": "ACTIVE", "tags": [ { "key": "project", "value": "lima" } ] "creationTime": 1565295733.282, "lastUpdatedTime": 1565295733.282 }, { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "name": "my-resource-share", "owningAccountId": "123456789012", "allowExternalPrincipals": true, "status": "ACTIVE", "creationTime": 1565295733.282, "lastUpdatedTime": 1565295733.282 } ] }

範例 2:列出其他人擁有並與您共用的資源共用

下列get-resource-shares範例會列出其他人建立並與您共用的資源共用。在這個例子中,沒有。

aws ram get-resource-shares \ --resource-owner OTHER-ACCOUNTS

輸出:

{ "resourceShares": [] }

下列程式碼範例會示範如何使用list-pending-invitation-resources

AWS CLI

若要列出擱置資源共用中可用的資源

下列list-pending-invitation-resources範例會列出與指定邀請相關聯之資源共用中的所有資源。

aws ram list-pending-invitation-resources \ --resource-share-invitation-arn arn:aws:ram:us-west-2:123456789012:resource-share-invitation/1e3477be-4a95-46b4-bbe0-c4001EXAMPLE

輸出:

{ "resources": [ { "arn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-04a555b0e6EXAMPLE", "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7be8694e-095c-41ca-9ce8-7be4aEXAMPLE", "creationTime": 1634676051.269, "lastUpdatedTime": 1634676052.07, "status": "AVAILABLE", "type": "ec2:Subnet" }, { "arn": "arn:aws:license-manager:us-west-2:123456789012:license-configuration:lic-36be0485f5ae379cc74cf8e92EXAMPLE", "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "creationTime": 1624912434.431, "lastUpdatedTime": 1624912434.431, "status": "AVAILABLE", "type": "license-manager:LicenseConfiguration" } ] }

下列程式碼範例會示範如何使用list-permissions

AWS CLI

列出可用的 RAM 管理權限

下列list-permissions範例會列出僅適用於 AWS Glue 資料庫資源類型的所有 RAM 管理權限。

aws ram list-permissions \ --resource-type glue:Database

輸出:

{ "permissions": [ { "arn": "arn:aws:ram::aws:permission/AWSRAMDefaultPermissionGlueDatabase", "version": "1", "defaultVersion": true, "name": "AWSRAMDefaultPermissionGlueDatabase", "resourceType": "glue:Database", "creationTime": 1592007820.935, "lastUpdatedTime": 1592007820.935, "isResourceTypeDefault": true }, { "arn": "arn:aws:ram::aws:permission/AWSRAMPermissionGlueAllTablesReadWriteForDatabase", "version": "2", "defaultVersion": true, "name": "AWSRAMPermissionGlueAllTablesReadWriteForDatabase", "resourceType": "glue:Database", "creationTime": 1624912413.323, "lastUpdatedTime": 1624912413.323, "isResourceTypeDefault": false }, { "arn": "arn:aws:ram::aws:permission/AWSRAMPermissionGlueDatabaseReadWrite", "version": "2", "defaultVersion": true, "name": "AWSRAMPermissionGlueDatabaseReadWrite", "resourceType": "glue:Database", "creationTime": 1624912417.4, "lastUpdatedTime": 1624912417.4, "isResourceTypeDefault": false }, { "arn": "arn:aws:ram::aws:permission/AWSRAMPermissionGlueTableReadWriteForDatabase", "version": "2", "defaultVersion": true, "name": "AWSRAMPermissionGlueTableReadWriteForDatabase", "resourceType": "glue:Database", "creationTime": 1624912434.431, "lastUpdatedTime": 1624912434.431, "isResourceTypeDefault": false } ] }

下列list-permissions範例顯示所有資源類型的可用 RAM 受管理權限。

aws ram list-permissions

輸出:

{ "permissions": [ { "arn": "arn:aws:ram::aws:permission/AWSRAMBlankEndEntityCertificateAPICSRPassthroughIssuanceCertificateAuthority", "version": "1", "defaultVersion": true, "name": "AWSRAMBlankEndEntityCertificateAPICSRPassthroughIssuanceCertificateAuthority", "resourceType": "acm-pca:CertificateAuthority", "creationTime": 1623264861.085, "lastUpdatedTime": 1623264861.085, "isResourceTypeDefault": false }, { "arn": "arn:aws:ram::aws:permission/AWSRAMDefaultPermissionAppMesh", "version": "1", "defaultVersion": true, "name": "AWSRAMDefaultPermissionAppMesh", "resourceType": "appmesh:Mesh", "creationTime": 1589307188.584, "lastUpdatedTime": 1589307188.584, "isResourceTypeDefault": true }, ...TRUNCATED FOR BREVITY... { "arn": "arn:aws:ram::aws:permission/AWSRAMSubordinateCACertificatePathLen0IssuanceCertificateAuthority", "version": "1", "defaultVersion": true, "name": "AWSRAMSubordinateCACertificatePathLen0IssuanceCertificateAuthority", "resourceType": "acm-pca:CertificateAuthority", "creationTime": 1623264876.75, "lastUpdatedTime": 1623264876.75, "isResourceTypeDefault": false } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListPermissions中的。

下列程式碼範例會示範如何使用list-principals

AWS CLI

若要列出具有資源存取權限的主參與者

下列list-principals範例顯示可透過任何資源共用存取指定類型之資源的主參與者清單。

aws ram list-principals \ --resource-type ec2:Subnet

輸出:

{ "principals": [ { "id": "arn:aws:organizations::123456789012:ou/o-gx7EXAMPLE/ou-29c5-zEXAMPLE", "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "creationTime": 1565298209.737, "lastUpdatedTime": 1565298211.019, "external": false } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListPrincipals中的。

下列程式碼範例會示範如何使用list-resource-share-permissions

AWS CLI

列出目前附加至資源共用的所有 RAM 管理權限

下列list-resource-share-permissions範例會列出所有附加至指定資源共用的 RAM 受管理權限。

aws ram list-resource-share-permissions \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/27d09b4b-5e12-41d1-a4f2-19dedEXAMPLE

輸出:

{ "permissions": [ { "arn": "arn:aws:ram::aws:permission/AWSRAMDefaultPermissionLicenseConfiguration", "version": "1", "resourceType": "license-manager:LicenseConfiguration", "status": "ASSOCIATED", "lastUpdatedTime": 1632342984.234 }, { "arn": "arn:aws:ram::aws:permission/AWSRAMPermissionGlueDatabaseReadWrite", "version": "2", "resourceType": "glue:Database", "status": "ASSOCIATED", "lastUpdatedTime": 1632512462.297 } ] }

下列程式碼範例會示範如何使用list-resource-types

AWS CLI

列出 AWS RAM 支援的資源類型

下列list-resource-types範例會列出 AWS RAM 目前支援的所有資源類型。

aws ram list-resource-types

輸出:

{ "resourceTypes": [ { "resourceType": "route53resolver:FirewallRuleGroup", "serviceName": "route53resolver" }, { "resourceType": "ec2:LocalGatewayRouteTable", "serviceName": "ec2" }, ...OUTPUT TRUNCATED FOR BREVITY... { "resourceType": "ec2:Subnet", "serviceName": "ec2" }, { "resourceType": "ec2:TransitGatewayMulticastDomain", "serviceName": "ec2" } ] }

下列程式碼範例會示範如何使用list-resources

AWS CLI

若要列出與資源共用相關聯的資源

下列list-resources範例會列出指定資源共用中指定資源類型的所有資源。

aws ram list-resources \ --resource-type ec2:Subnet \ --resource-owner SELF \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE

輸出:

{ "resources": [ { "arn": "aarn:aws:ec2:us-west-2:123456789012:subnet/subnet-0250c25a1f4e15235", "type": "ec2:Subnet", "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "creationTime": 1565301545.023, "lastUpdatedTime": 1565301545.947 } ] }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListResources中的。

下列程式碼範例會示範如何使用promote-resource-share-created-from-policy

AWS CLI

將以資源原則為基礎的資源共用提升為 RAM 中的完整功能 AWS

下列promote-resource-share-created-from-policy範例會採用您透過附加以資源為基礎的原則以隱含方式建立的資源共用,並將其轉換為可與 AWS RAM 主控台及其 CLI 和 API 作業完整運作。

aws ram promote-resource-share-created-from-policy \ --resource-share-arn arn:aws:ram:us-east-1:123456789012:resource-share/91fa8429-2d06-4032-909a-90909EXAMPLE

輸出:

{ "returnValue": true }

下列程式碼範例會示範如何使用reject-resource-share-invitation

AWS CLI

拒絕資源共用邀請

下列reject-resource-share-invitation範例會拒絕指定的資源共用邀請。

aws ram reject-resource-share-invitation \ --resource-share-invitation-arn arn:aws:ram:us-west-2:111111111111:resource-share-invitation/32b639f0-14b8-7e8f-55ea-e6117EXAMPLE

輸出:

"resourceShareInvitations": [ { "resourceShareInvitationArn": "arn:aws:ram:us-west2-1:111111111111:resource-share-invitation/32b639f0-14b8-7e8f-55ea-e6117EXAMPLE", "resourceShareName": "project-resource-share", "resourceShareArn": "arn:aws:ram:us-west-2:111111111111:resource-share/fcb639f0-1449-4744-35bc-a983fEXAMPLE", "senderAccountId": "111111111111", "receiverAccountId": "222222222222", "invitationTimestamp": 1565319592.463, "status": "REJECTED" } ]

下列程式碼範例會示範如何使用tag-resource

AWS CLI

若要將標籤新增至資源共用

下列tag-resource範例會將標籤索引鍵project和關聯值新增lima至指定的資源共用。

aws ram tag-resource \ --tags key=project,value=lima \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE

此命令不會產生輸出。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考TagResource中的。

下列程式碼範例會示範如何使用untag-resource

AWS CLI

若要從資源共用中移除標籤

下列untag-resource範例會從指定的資源共用中移除project標籤索引鍵和關聯值。

aws ram untag-resource \ --tag-keys project \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE

此命令不會產生輸出。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考UntagResource中的。

下列程式碼範例會示範如何使用update-resource-share

AWS CLI

若要更新資源共用

下列update-resource-share範例會變更指定的資源共用,以允許不在 AWS 組織中的外部主參與者。

aws ram update-resource-share \ --allow-external-principals \ --resource-share-arn arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE

輸出:

{ "resourceShare": { "resourceShareArn": "arn:aws:ram:us-west-2:123456789012:resource-share/7ab63972-b505-7e2a-420d-6f5d3EXAMPLE", "name": "my-resource-share", "owningAccountId": "123456789012", "allowExternalPrincipals": true, "status": "ACTIVE", "creationTime": 1565295733.282, "lastUpdatedTime": 1565303080.023 } }