【发布时间】:2018-03-08 19:19:29
【问题描述】:
我使用 Cognito 中的 token_id 成功设置了对 Lambda 的访问 - 客户端添加标头 Authorization: <token_id> 并且 Api Gateway 验证此令牌。我希望我可以从客户端浏览器设置对 S3 的类似访问。为此,我为 S3 存储桶编写了策略(每个用户都有自己的文件目录):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "cognito-identity.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::buc/${cognito-identity.amazonaws.com:sub}/*"
}
]
}
我试过这个电话:
curl -v --header 'Authorization: [id_token_from_cognito_after_signup]' https://s3.amazonaws.com/buc/<sub>/myfile.jpg
返回 400 Authorization header is invalid -- one and only one ' ' (space) required。在网上我发现这个错误可能与空格无关 - 因为这个请求有正确的空格数量(我也试过没有空格的请求)。
有趣的是,在documentation 中关于 S3 并没有提到 Cognito。
为了速度和简单性,我不想在客户端使用 js sdk。
【问题讨论】:
-
我有理由确定您需要使用 cognito 凭据来为 S3 创建签名请求——而不是直接发送令牌。
标签: amazon-web-services amazon-s3 amazon-cognito