Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PermanentRedirect while generating pre signed url

I am having an issue while creating a pre signed url from aws s3 using aws-sdk in nodejs. It gives me PermanentRedirect The bucket you are attempting to access must be addressed using the specified endpoint.

    const s3 = new AWS.S3()
    AWS.config.update({accessKeyId: 'test123', secretAccessKey: 'test123'})

    AWS.config.update({region: 'us-east-1'})

    const myBucket = 'test-bucket'
    const myKey = 'test.jpg'
    const signedUrlExpireSeconds = 60 * 60

    const url = s3.getSignedUrl('getObject', {
        Bucket: myBucket,
        Key: myKey,
        Expires: signedUrlExpireSeconds
    })
    console.log(url)

How I can remove this error to get pre signed url working. Also I need to know what is a purpose of Key.

like image 522
JN_newbie Avatar asked Apr 21 '26 14:04

JN_newbie


1 Answers

1st - what is your region of the bucket? S3 is global service yet each bucket has region, while creating the bucket you must select it.

enter image description here

2nd - when working with S3 not in N.Virginia region there could be situations when internal aws SSL/DNS is not in sync yet. I had this issue multiple times, can't find exact docs related to this but issue is from nature of redirects, not found or no access. Then after 4-12h it starts to just work. What i happen to dig out about these issues is something related to internal AWS SSL/DNS related to S3 buckets that are not in n.virginia region. So could be it.

3rd - If you re-created buckets multiple times and re-using same name. Bucket name is global, even if bucket is regional. So could be again related to 2nd scenarios when previously within last 24h bucket was actually on different region and now AWS's internal DNS/SSL haven't synced yet.

p.s. Key is object's key, any object inside bucket has key. On aws console you can navigate "key" which looks like path to file, but it's not a path to file. S3 has no concept of directories like hard drives. Any path to file is a key of object. AWS console just splits object's key by / and displays as directories to have better UX while navigating the UI.

like image 167
Lukas Liesis Avatar answered Apr 24 '26 03:04

Lukas Liesis