

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

# 列出呼叫者的存取授權
<a name="access-grants-list-grants"></a>

S3 資料擁有者可以使用 S3 存取授權來建立 AWS Identity and Access Management (IAM) 身分或 AWS IAM Identity Center 公司目錄身分的存取授權。IAM 身分和 IAM Identity Center 目錄身分可以接著使用 `ListCallerAccessGrants` API 來列出其可存取的 Amazon S3 儲存貯體、字首和物件 (就如其 S3 存取授權所定義的一樣)。使用此 API 來探索 IAM 或目錄身分可以透過 S3 存取授權存取的所有 S3 資料。

您可以使用此功能來建置應用程式，以顯示特定最終使用者可存取的資料。例如，S3 的 AWS Storage Browser 是客戶用來存取 S3 儲存貯體的開放原始碼 UI 元件，它使用此功能來向最終使用者提供他們根據 S3 Access Grants 在 Amazon S3 中可存取的資料。另一個範例是在建置應用程式以在 Amazon S3 中瀏覽、上傳或下載資料時，您可以使用此功能在應用程式中建置樹狀結構，讓最終使用者能夠接著瀏覽。

**注意**  
對於公司目錄身分，列出呼叫者的存取授權時，S3 存取授權會傳回用於身分感知工作階段的 IAM 身分的授權。如需有關身分感知工作階段的詳細資訊，請參閱《AWS Identity and Access Management 使用者指南》**中的[授予權限以使用身分感知主控台工作階段](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_sts-setcontext.html)。

無論承授者是 IAM 身分還是公司目錄身分，都可以使用 AWS Command Line Interface (AWS CLI)、Amazon S3 REST API 和 AWS SDKs 取得其存取授權的清單。

## 使用 AWS CLI
<a name="access-grants-list-grants-cli"></a>

若要安裝 AWS CLI，請參閱*AWS Command Line Interface 《 使用者指南*[》中的安裝 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) 。

若要使用下列範例命令，請以您自己的資訊取代 `{{user input placeholders}}`。

**Example 列出呼叫者的存取授權**  
要求:  

```
aws s3control list-caller-access-grants \
--account-id {{111122223333}} \
--region {{us-east-2}}
--max-results 5
```
回應：  

```
{
	"NextToken": "{{6J9S...}}",
	"CallerAccessGrantsList": [
		{
			"Permission": "READWRITE",
			"GrantScope": "s3://{{amzn-s3-demo-bucket}}/{{prefix1/}}{{sub-prefix1/}}*",
			"ApplicationArn": "NA"
		},
		{
			"Permission": "READWRITE",
			"GrantScope": "s3://{{amzn-s3-demo-bucket}}/{{prefix1/}}{{sub-prefix2/}}*",
			"ApplicationArn": "ALL"
		},
		{
			"Permission": "READWRITE",
			"GrantScope": "s3://{{amzn-s3-demo-bucket}}/{{prefix1/}}{{sub-prefix3/}}*",
			"ApplicationArn": "arn:aws:sso::{{111122223333}}:application/ssoins-ssoins-{{1234567890abcdef/apl-abcd1234a1b2c3d}}"
		}
	]
}
```

**Example 列出呼叫者對儲存貯體的存取授權**  
您可使用 `grantscope` 參數來縮小結果範圍。  
要求:  

```
aws s3control list-caller-access-grants \
--account-id {{111122223333}} \
--region {{us-east-2}}
--grant-scope "{{s3://{{amzn-s3-demo-bucket}}}}""
--max-results 1000
```
回應：  

```
{
	"NextToken": "{{6J9S...}}",
	"CallerAccessGrantsList": [
		{
			"Permission": "READ",
			"GrantScope": "s3://{{amzn-s3-demo-bucket}}*",
			"ApplicationArn": "ALL"
		},
		{
			"Permission": "READ",
			"GrantScope": "s3://{{amzn-s3-demo-bucket}}/{{prefix1/}}*",
			"ApplicationArn": "arn:aws:sso::{{111122223333}}:application/ssoins-ssoins-{{1234567890abcdef/apl-abcd1234a1b2c3d}}"
		}
	]
}
```

## 使用 REST API
<a name="access-grants-list-grants-rest-api"></a>

如需取得 API 呼叫者存取授權清單的 Amazon S3 REST API 支援資訊，請參閱 Amazon Simple Storage Service API 參考**中的 [ListCallerAccessGrants](https://docs.aws.amazon.com/AmazonS3/latest/API/API_control_ListCallerAccessGrants.html)。

## 使用 AWS SDKs
<a name="access-grants-list-grants-using-sdk"></a>

本節提供承授者如何使用 AWS SDKs 從 S3 Access Grants 請求臨時憑證的範例。

------
#### [ Java ]

下列程式碼範例會傳回 API 呼叫者的存取授權給特定 的 S3 資料 AWS 帳戶。若要使用此程式碼範例，請將 `{{user input placeholders}}` 取代為您自己的資訊。

**Example 列出呼叫者的存取授權**  
要求:  

```
Public void ListCallerAccessGrants() {
	ListCallerAccessGrantsRequest listRequest = ListCallerAccessGrantsRequest.builder()
				.withMaxResults(1000)
				.withGrantScope("{{s3://}}")
				.accountId("{{111122223333}}");
	ListCallerAccessGrantsResponse listResponse = s3control.listCallerAccessGrants(listRequest);
	LOGGER.info("ListCallerAccessGrantsResponse: " + listResponse);
	}
```
回應：  

```
ListCallerAccessGrantsResponse(
CallerAccessGrantsList=[
	ListCallerAccessGrantsEntry(
		S3Prefix=s3://{{amzn-s3-demo-bucket}}/{{prefix1/}},
		Permission=READ,
		ApplicationArn=ALL
	)
])
```

------