amazon web services - AWS S3 Policy wildcard ("*") works, but "s3:GetObject", "s3:PutObject", etc does not -
by following example here uploading photos amazon s3 browser able upload files browser s3 bucket. however, when attempt modify policy more specific addeing following statement access denied error:
{ "effect": "allow", "action": [ "s3:getobject", "s3:putobject", "s3:deleteobject" ], "resource": [ "arn:aws:s3:::[my_bucket]/${cognito-identity.amazonaws.com:sub}", "arn:aws:s3:::[my_bucket]/${cognito-identity.amazonaws.com:sub}*" ] }
however, following statement allow me upload bucket:
{ "effect": "allow", "action": [ "*" ], "resource": [ "arn:aws:s3::[my_bucket]/${cognito-identity.amazonaws.com:sub}", "arn:aws:s3:::[my_bucket]/${cognito-identity.amazonaws.com:sub}*" ] }
i logging in user using federated login , placing them aws identity pool. policy containing above code assumed authenticated role of identity pool. i've confirmed identity id exists in identity pool. research tells me should able more specific actions have no idea going wrong here.
edit:
i realized might useful know how files got in bucket in first place. i'm using aws-sdk npm , following code upload image files bucket:
return new promise(function (resolve, reject) { const filename = userid + '/' + utilities.getguid(); s3.upload({ key: filename, body: file, acl: 'public-read' }, function (err, data) { if (err) { dropzoneutilities.setdropzonefilecanceled(file); console.log(err); reject(err); } else { dropzoneutilities.setdropzonefilecomplete(file); dropzoneutilities.removefile(file); resolve({ data, name: file.name}); } }); });
note in upload code:
acl: 'public-read'
the documentation not unambiguous on point, including requires s3:putobjectacl
permission.
Comments
Post a Comment