> For the complete documentation index, see [llms.txt](https://academy.shade.inc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://academy.shade.inc/shade-academy/shade-academy-zh/zi-dai-cun-chu/connecting-shade-with-aws-s3.md).

# 将 Shade 连接到 AWS S3

**创建存储桶**

1. 创建一个存储桶。记下你创建的区域和存储桶名称
   1. 只需更改存储桶名称输入即可。所有其他默认设置都可以保持不变（通用用途、无 ACL、阻止所有公共访问、无存储桶版本控制、服务器端加密、无高级设置）

**CORS 配置**

1. 点击进入存储桶，然后点击权限选项卡。滚动到 `跨域资源共享（CORS）` 部分。

<figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FkGVNB69nqWLvUWJIWdNT%2Fimage.png?alt=media&amp;token=857eb17c-3f40-45eb-a29f-f6dac0bcf606" alt=""><figcaption></figcaption></figure>

2\. 点击编辑，然后粘贴此 JSON。

{% code fullWidth="false" %}

```
[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "DELETE",
            "HEAD"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [
            "ETag",
            "Content-Length",
            "Content-Disposition",
            "Content-Encoding",
            "x-amz-request-id",
            "x-amz-id-2",
            "x-amz-version-id",
            "x-amz-server-side-encryption"
        ],
        "MaxAgeSeconds": 3000
    }
]
```

{% endcode %}

此 JSON 用于允许网页浏览器访问此存储桶。这是安全的，因为我们通过自己的服务器提供重定向，同时保持 CORS 权限的特定范围，因此此配置可以保持通用。

**创建作用域策略**

1. 在 `IAM` 点击 `策略` 然后点击 `创建策略`

   1. 我们看到的大多数错误都发生在这里，即策略没有正确自定义

   <figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FnZIqNYO9wGBNJ2vby63E%2Fimage.png?alt=media&amp;token=406f35f0-121f-4ce0-a612-7ae0962a6973" alt=""><figcaption></figcaption></figure>
2. 请确保自定义下面这个 JSON 文件，以更改 `Resource` 条目，从 `the-bucket-name-you-provisioned-earlier` 改为你最初创建的存储桶名称。 **这在两个地方：一个在 `bucketname` 资源下，另一个在 `bucketname/*` 资源下**

```
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Action": [
				"s3:ListBucket",
				"s3:GetBucketLocation"
			],
			"Resource": "arn:aws:s3:::the-bucket-name-you-provisioned-earlier"
		},
		{
			"Effect": "Allow",
			"Action": [
				"s3:GetObject",
				"s3:PutObject",
				"s3:DeleteObject"
			],
			"Resource": "arn:aws:s3:::the-bucket-name-you-provisioned-earlier/*"
		}
	]
}
```

3. 使用 JSON 编辑器并将其粘贴到策略编辑器中
4. 将你的策略命名为与我们之前创建的 Shade 存储桶访问相关的名称，并添加描述。创建策略

**创建用户**

1. 现在在 `用户` 中，在 IAM 左侧边栏点击 `创建用户`
2. 给用户起一个与 Shade 相关的名称。这个用户将是 Shade 服务器通过其访问你的存储桶并签名 URL 的用户。
3. 选择 `直接附加策略` 并找到你创建的策略。勾选复选框以附加它，然后点击下一步

<figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FRuj9ZkYDTY3ECZR8GLEk%2Fimage.png?alt=media&amp;token=dfa64253-4a6a-40fa-9951-5403053cbd3d" alt=""><figcaption></figcaption></figure>

4. 创建用户
5. 现在点击该用户并点击 `创建访问密钥`

<figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FhcWU9ZUSgzxCd7BbAmKJ%2Fimage.png?alt=media&amp;token=b1f860f0-ec54-4de2-b5ec-a695996ad47a" alt=""><figcaption></figcaption></figure>

6. 选择 `在 AWS 外部运行的应用程序`

<figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FkuUWTk7seBrTDBVIcB6s%2Fimage.png?alt=media&amp;token=5675b7ae-ed8a-4435-bf89-37461a9bc3df" alt=""><figcaption></figcaption></figure>

7. 将创建的访问密钥和密钥保存到你的电脑中

**在 Shade 中创建驱动器**

1. 在 Shade 应用中创建一个 BYOS 驱动器

<figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FV0QizFJMF15OW53AI0bP%2Fimage.png?alt=media&amp;token=33a55b13-064d-4e53-be9f-f8959a8a844d" alt=""><figcaption></figcaption></figure>

2. 使用 `自定义` 配置来创建你的存储桶
3. 用正确的值填写配置。注意端点。使用带有 `s3.<region>.amazonaws.com` 前缀的 `https://`格式。根据你创建存储桶所在的区域，在此页面下查找这些端点： `Amazon S3 endpoints` ： <https://docs.aws.amazon.com/general/latest/gr/s3.html>

<figure><img src="https://3843445310-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUNq6h2Bfw7aAK0J2ffnZ%2Fuploads%2FAhQJ4Q5zd8dkAY6KFUCy%2Fimage.png?alt=media&amp;token=21846f1c-1011-4eab-8fd7-5526cb58cb35" alt=""><figcaption></figcaption></figure>

4. 上传一个文件进行测试。你应该会看到对象出现在你的 S3 存储桶中，文件应能正常上传并正常获得预览/代理。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://academy.shade.inc/shade-academy/shade-academy-zh/zi-dai-cun-chu/connecting-shade-with-aws-s3.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
