AWS presigned URLS location constraint is incompatible for the region specific endpoint this request was sent to

I am using a lambda to create a presigned URL to download files that land in an S3 bucket - the code works and I get a URL but when trying to access it I get "af-south-1 location constraint is incompatible for the region specific endpoint this request was sent to." both the bucket and the lamda are in the same region I'm at a loss as to what is actually happening any ideas or solutions would be greatly appreciated.

my code is below

import json
import boto3
import boto3.session


def lambda_handler(event, context):
    session = boto3.session.Session(region_name='af-south-1')
    s3 = session.client('s3')
    for record in event['Records']:
        bucket = record['s3']['bucket']['name']
        key = record['s3']['object']['key']

    url = s3.generate_presigned_url(ClientMethod='get_object',
                                    Params={'Bucket': bucket,
                                    'Key': key}, ExpiresIn = 400)
    print (url)```


Read more here: https://stackoverflow.com/questions/64891466/aws-presigned-urls-location-constraint-is-incompatible-for-the-region-specific-e

Content Attribution

This content was originally published by Maxui at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: