question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any method to get s3 endpoint url for a given region?

See original GitHub issue

Hi, I’m curious if there is any way in the library to get the endpoint for s3 in a given region? I need to generate the template url for cloudformation [create/update]_stack calls. Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
kichikcommented, Apr 28, 2020

I’m not sure when this was added, but you can now use client.meta.endpoint_url:

import boto3
import urllib.parse

ep = boto3.client("s3", region_name="eu-west-1").meta.endpoint_url
ep = urllib.parse.urlparse(ep).hostname
3reactions
dstufftcommented, Jul 6, 2017

Ok, the answer is there isn’t a direct function, but you can load all of that data using:

import botocore.loaders

loader = botocore.loaders.create_loader()
data = loader.load_data("endpoints")

# At this point, you have a big data structure which isn't great
# to work with. However, there is an API you can use to work with
# it, but it's undocumented so it might change in the future.

import botocore.regions

resolver = botocore.regions.EndpointResolver(data)
endpoint_data = resolver.construct_endpoint("s3", "us-east-1")

# At this point, you have endpoint_data which contains something like:
{
    'hostname': 's3.amazonaws.com',
    'signatureVersions': ['s3', 's3v4'],
    'partition': 'aws',
    'endpointName': 'us-east-1',
    'protocols': ['http', 'https'],
    'dnsSuffix': 'amazonaws.com',
}

# At this point, you can do some basic url generation to get the URL.

Besides that, I don’t believe there is any other way to get at this programatically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Website endpoints - Amazon Simple ... - AWS Documentation
Configure an Amazon S3 bucket for website hosting to make it available through the AWS Region-specific website endpoint.
Read more >
How to get S3 endpoint using aws region in AWS cli?
I want to get the endpoint of a given ...
Read more >
How to Allow Public Access to an Amazon S3 Bucket & Find ...
1. Click on the bucket name from the list of S3 buckets. · 2. Go to the Properties tab. · 3. Click on...
Read more >
Troubleshoot endpoint URL connection error in Amazon S3
When you run a command using the AWS CLI, API requests are sent to the default AWS Region's S3 endpoint. Or, API requests...
Read more >
How to fix could not connect to the endpoint URL issue in S3?
Buckets are tied to regions in Amazon S3. So when we are using AWS CLI, we need to configure it to use a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found