如何使用 aws s3api 设置元数据?
How do I set metadata with aws s3api?
我正在尝试将我的 CloudFront 托管博客重定向 /feed/atom/index.html
到 /index.xml
。我有以下脚本应该为我设置重定向 headers:
#!/bin/sh
redirect() aws s3api copy-object \
--copy-source blog.afoolishmanifesto.com \
--bucket blog.afoolishmanifesto.com --key \
--metadata x-amz-website-redirect-location= \
--metadata-directive REPLACE
redirect /feed/atom/index.html /index.xml
在 运行 脚本之后我得到以下输出:
{
"CopyObjectResult": {
"LastModified": "2016-03-27T07:26:03.000Z",
"ETag": "\"40c27e3a5ea160c6695d7f34de8b4dea\""
}
}
当我在 S3 的 AWS 控制台视图中刷新 object 时,我没有看到 object 的 Website Redirect Location
(或 x-amz-website-redirect-location
)元数据有问题。我该怎么做才能确保正确配置重定向?
注意:我已尝试将元数据指定为 JSON,据我所知没有任何区别。
更新: 我保留了上述问题不变,因为它仍然适用于元数据,但是如果您尝试使用 aws s3api 创建重定向,您应该使用 --website-redirect-location
选项,而不是 --metadata
.
无法在存储桶中创建键 /feed/atom/index.html
,因此未创建元数据属性。相反,您应该创建 feed/atom/index.html
。我会像这样修改它:
#!/bin/sh
redirect() aws s3api copy-object \
--copy-source blog.afoolishmanifesto.com/ \
--bucket blog.afoolishmanifesto.com --key \
--metadata x-amz-website-redirect-location= \
--metadata-directive REPLACE
redirect feed/atom/index.html /index.xml
在我的解决方案中,请注意 --copy-source
中的 /
以及重定向脚本的第一个参数缺少前导 /
我正在尝试将我的 CloudFront 托管博客重定向 /feed/atom/index.html
到 /index.xml
。我有以下脚本应该为我设置重定向 headers:
#!/bin/sh
redirect() aws s3api copy-object \
--copy-source blog.afoolishmanifesto.com \
--bucket blog.afoolishmanifesto.com --key \
--metadata x-amz-website-redirect-location= \
--metadata-directive REPLACE
redirect /feed/atom/index.html /index.xml
在 运行 脚本之后我得到以下输出:
{
"CopyObjectResult": {
"LastModified": "2016-03-27T07:26:03.000Z",
"ETag": "\"40c27e3a5ea160c6695d7f34de8b4dea\""
}
}
当我在 S3 的 AWS 控制台视图中刷新 object 时,我没有看到 object 的 Website Redirect Location
(或 x-amz-website-redirect-location
)元数据有问题。我该怎么做才能确保正确配置重定向?
注意:我已尝试将元数据指定为 JSON,据我所知没有任何区别。
更新: 我保留了上述问题不变,因为它仍然适用于元数据,但是如果您尝试使用 aws s3api 创建重定向,您应该使用 --website-redirect-location
选项,而不是 --metadata
.
无法在存储桶中创建键 /feed/atom/index.html
,因此未创建元数据属性。相反,您应该创建 feed/atom/index.html
。我会像这样修改它:
#!/bin/sh
redirect() aws s3api copy-object \
--copy-source blog.afoolishmanifesto.com/ \
--bucket blog.afoolishmanifesto.com --key \
--metadata x-amz-website-redirect-location= \
--metadata-directive REPLACE
redirect feed/atom/index.html /index.xml
在我的解决方案中,请注意 --copy-source
中的 /
以及重定向脚本的第一个参数缺少前导 /