zeus
zeus

Reputation: 137

Static files in Django with AWS S3

I just moved the static files of my Django project into AWS S3. It works so far. But my .css files contain relative paths, for example to fonts, for example:

@import "variables";

@font-face {
  font-family: '#{$font-family}';
  src:  url('#{$font-path}/#{$font-family}.eot?4zay6m');
  format('svg');
  font-weight: normal;
  font-style: normal;
}

My browser console shows that the path to these file is set correctly, for example

https://mybucket.s3.amazonaws.com/static/plugins/fonts/myfont.ttf?4zay6m

but I get a permission denied, because unlike the other (from django set paths), these paths do not contain the "Amazon stuff" after the question mark like

https://mybucket.s3.amazonaws.com/static/js/jquery.tablednd.js?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=XXXXXXX

Is there a simple workaroud?

Thanks in advance.

Upvotes: 1

Views: 790

Answers (1)

Avinash Dalvi
Avinash Dalvi

Reputation: 9301

You can do solve your problem using :

  1. Set S3 bucket as static web hosting: Bucket -> Properties -> Static website hosting -> Set root file and error file as index.html
  2. Use public end point as URL to access your content like css, js or images

Your S3 is not public static hosting to access without Access token of AWS account.

For example how to do S3 bucket as hosting see this blog : https://www.internetkatta.com/host-angular-2-or-4-or-5-version-in-aws-s3-using-cloudfront

Upvotes: 1

Related Questions