Accessing a us-west-2 S3 bucket using Amazon Cognito and an IAM policy -


amazon cognito available in 2 zones: us-east-1 , eu-west-1
have bucket in us-west-2

here iam policy have unauthenticated guests in cognito identity pool:

{     "version": "2012-10-17",     "statement": [         {             "effect": "allow",             "action": [                 "s3:putobject",                 "s3:putobjectacl"             ],             "resource": [                 "arn:aws:s3:::vocal.test14/*"             ]         }     ] } 

during uploading, i'm not able access s3 bucket
stated here, should possible:

what rule need add policy give cognito ability communicate bucket that's not in us-east?


someone asked more information, here is:

i've created new bucket called vocal.west2
i've given bucket following cors properties:

<?xml version="1.0" encoding="utf-8"?> <corsconfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">     <corsrule>         <allowedorigin>https://domain.com</allowedorigin>         <allowedorigin>https://*.domain.com</allowedorigin>         <allowedmethod>get</allowedmethod>         <allowedheader>authorization</allowedheader>         <maxageseconds>3000</maxageseconds>     </corsrule>     <corsrule>         <allowedorigin>https://domain.com</allowedorigin>         <allowedorigin>https://*.domain.com</allowedorigin>         <allowedmethod>post</allowedmethod>         <allowedmethod>put</allowedmethod>         <allowedheader>*</allowedheader>         <exposeheader>etag</exposeheader>         <maxageseconds>3000</maxageseconds>     </corsrule> </corsconfiguration> 

i've updated iam role following:

{     "version": "2012-10-17",     "statement": [         {             "effect": "allow",             "action": [                 "s3:putobject",                 "s3:putobjectacl"             ],             "resource": [                 "arn:aws:s3:::vocal.west2/*"             ]         }     ] } 

i'm attempting upload file using aws javascript sdk. code pretty long, here cognito credential call:

aws.config.region = 'us-east-1'; aws.config.credentials = new aws.cognitoidentitycredentials({     identitypoolid: 'us-east-1:rest-of-id-here' }); 

note region set 1us-east-1`, that's because it's referencing cognito zone, not s3 bucket.

note actual js code doing upload works fine when it's us-east-1 bucket.

resolved:

i'm using aws.s3.managedupload lib.
in order specify s3 zone, aws.s3 object needs created (case matters here; doesn't work aws.s3)

here aws.s3 object instantiation:

var s3 = (new aws.s3({     region: 'us-west-2' })) 

here aws.s3.managedupload instantiation:

var upload = (new aws.s3.managedupload({     params: {         bucket: 'vocal.test14',         key: 'filename',         body: file,         contenttype: 'image/jpeg',         acl: 'public-read'     },     service: s3 })); 

and here logic upload/report progress:

upload.on('httpuploadprogress', function(event) {     console.log(         'progress:',         event.loaded,         '/',         event.total     ); }); upload.send(function(err, data) {     if (data) {         console.log('uploaded');         console.log(data);     } else {         console.log(arguments);     } }); 

thanks @mark-mercurio help


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -