> 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/byos/jiang-shade-lian-jie-dao-aws-s3.md).

# 将 Shade 连接到 AWS S3

**创建存储桶**

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

**CORS 配置**

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

<figure><img src="/files/c037d6eca96ad56360bf473f9ba43c4342607161" 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="/files/cdf030ebdc4431e3f5346063159301bb88be256e" alt=""><figcaption></figcaption></figure>
2. 请务必自定义下面这个 JSON 文件，以更改 `资源` 条目，从 `你之前配置的存储桶名称` 改为你最初创建的存储桶名称。 **这在两个地方：一个在 `bucketname` 资源下，另一个在 `bucketname/*` 资源下**

```
{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Action": [
				"s3:ListBucket",
				"s3:GetBucketLocation"
			],
			"Resource": "arn:aws:s3:::你之前配置的存储桶名称"
		},
		{
			"Effect": "Allow",
			"Action": [
				"s3:GetObject",
				"s3:PutObject",
				"s3:DeleteObject"
			],
			"Resource": "arn:aws:s3:::你之前配置的存储桶名称/*"
		}
	]
}
```

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

**创建用户**

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

<figure><img src="/files/e9dcbe267dfe4ef8db237dfc28cd2fb6929b1360" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/b24aeaed3617429a1c3fa9a2e0d89c7352421c77" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/0b53fb1bd66059d89365dd4680bd1f29929caed9" alt=""><figcaption></figcaption></figure>

7. 将创建的 Access 和 Secret 密钥保存到你的电脑上

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

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

<figure><img src="/files/d67a1dd4e064e672d55dc672685a48ac416ab2e6" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/8cb8a70225663e03de7b60991c2f505a24091861" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://academy.shade.inc/shade-academy/shade-academy-zh/byos/jiang-shade-lian-jie-dao-aws-s3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
