DO Spaces on Django Cookiecutter Docker - AWS Connection Issue

20 Views Asked by At

I am trying to run DO Spaces on a Django/Docker. (setup via Django-Cookiecutter.)

I know all this data is good.

DJANGO_AWS_ACCESS_KEY_ID='DO00CBN....BATCXAE'
DJANGO_AWS_SECRET_ACCESS_KEY='vkmMV3Eluv8.....U1nvalkSFugkg'
DJANGO_AWS_STORAGE_BUCKET_NAME='my-key'
DJANGO_AWS_DEFAULT_ACL = 'public-read'
DJANGO_AWS_S3_REGION_NAME = 'sgp1'

DJANGO_AWS_S3_CUSTOM_DOMAIN = 'https://my-key.sgp1.digitaloceanspaces.com'

in production.py

AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
AWS_QUERYSTRING_AUTH = False
_AWS_EXPIRY = 60 * 60 * 24 * 7
AWS_S3_OBJECT_PARAMETERS = {
    "CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate",
}
AWS_S3_MAX_MEMORY_SIZE = env.int( "DJANGO_AWS_S3_MAX_MEMORY_SIZE",
    default=100_000_000,  # 100MB)
AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None)
AWS_S3_CUSTOM_DOMAIN = env("DJANGO_AWS_S3_CUSTOM_DOMAIN", default=None)

# aws_s3_domain = AWS_S3_CUSTOM_DOMAIN or f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"
aws_s3_domain = AWS_S3_CUSTOM_DOMAIN or f"{AWS_STORAGE_BUCKET_NAME}.digitaloceanspaces.com"

I chaged the '.s3.amazonaws.com' to '.digitaloceanspaces.com' which gives me 'https://my-zzz.sgp1.digitaloceanspaces.com'

But nothing i do or change makes a difference and I always get this error.

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://my-key.s3.sgp1.amazonaws.com/static/sass/project.scss"

It seems that the connection is always being overwritten by the '.s3.sgp1.amazonaws.com'

What can I do to change this setting which seems to happen in boto?

remember this is via Docker. Can it be done via an enviorment in the production.yml? Or in the AWS Dockerfile?

Thanks!

1

There are 1 best solutions below

0
diogenes On

ok, after a lot of trail and error it came down to a combinations of things.

the .production

DJANGO_AWS_ACCESS_KEY_ID='DO...KJ4ZY4'
DJANGO_AWS_SECRET_ACCESS_KEY='0AoD...F2HNPM'
DJANGO_AWS_STORAGE_BUCKET_NAME='bucket-name'
DJANGO_AWS_DEFAULT_ACL = 'public-read'
DJANGO_AWS_S3_REGION_NAME = 'sgp1'
DJANGO_AWS_S3_CUSTOM_DOMAIN = 'appname.sgp1.digitaloceanspaces.com'

the production.py

AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None)
AWS_S3_CUSTOM_DOMAIN = env("DJANGO_AWS_S3_CUSTOM_DOMAIN", default=None)
AWS_S3_ENDPOINT_URL = 'https://sgp1.digitaloceanspaces.com'
aws_s3_domain = AWS_S3_CUSTOM_DOMAIN or f"{AWS_STORAGE_BUCKET_NAME}.digitaloceanspaces.com"

I hope this helps and would appreciate any ideas on updating this code. IT is not my thing.

Be so easy for django-cookiecutter to make Spaces a setup option like AWS. Hint, hint...