AWS S3
Boto
Heroku
Naming Conventions
Connection Issues

Can't connect to S3 buckets with periods in their name, when using Boto on Heroku

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Boto is a popular Python library that provides an interface to connect applications with Amazon Web Services (AWS) services, including Amazon Simple Storage Service (S3). However, users deploying applications on Heroku sometimes encounter difficulties when their S3 buckets have periods in their names. This issue specifically concerns how DNS resolves bucket names and interacts with TLS certificates, leading to problems in establishing a successful connection.

Understanding the Problem

DNS Compatibility with Bucket Names

Amazon S3 bucket names must comply with DNS naming conventions. While AWS allows bucket names with periods (e.g., `example.bucket.com`), this can cause complications with the Domain Name System (DNS) and TLS/SSL when accessing the buckets using `path-style` or `virtual-hosted–style` URLs.

Virtual-Hosted vs. Path-Style URLs

  • Virtual-Hosted–Style: The bucket name is included in the hostname (`https://example.bucket.com.s3.amazonaws.com/object\`). In this style, DNS has to resolve the entire URL, including periods, which can complicate matters with TLS/SSL certificates because the wildcard `*.s3.amazonaws.com` certificate can't cover periods in subdomains.
  • Path-Style: The bucket name is part of the path instead (`https://s3.amazonaws.com/example.bucket.com/object\`). AWS announced in 2020 that path-style URLs have been deprecated for new regions, pushing users towards the virtual-hosted–style.

TLS/SSL Issues

When using virtual-hosted–style URLs with bucket names that contain periods, the AWS TLS/SSL certificates may not properly match the domain. This mismatch occurs because the certificate provided by AWS only covers the S3 service itself (`*.s3.amazonaws.com`), but not specific bucket names that have periods.

Boto's Role and Impact on Heroku

When deploying applications using Boto on Heroku, developers often rely on the virtual-hosted–style URLs due to Heroku environments not supporting path-style URLs efficiently with the deprecated status. If bucket names contain periods, this may lead to certificate verification failures and inability to connect to S3 buckets.

Technical Solutions and Workarounds

Renaming Buckets

A straightforward solution involves renaming buckets to exclude periods. This sidesteps the DNS and TLS issues altogether but may not be feasible for established applications.

Using Custom Domain Endpoints

Instead of connecting directly to `s3.amazonaws.com`, one can set a custom domain that points to the S3 bucket:

  • Point a CNAME record from a custom domain to your bucket (e.g., `example.com` to `example.bucket.com`).
  • Use a TLS/SSL certificate that matches your custom domain.

Modifying Boto Configuration

Configure Boto to force path-style access (only for older regions) by setting `use_path_style_endpoint = True` in the Boto configuration file or programmatically:


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design