amazon-web-servicesdjango-rest-frameworkaws-lambdastaticzappa

AWS Zappa static files


I'm trying to create my first app with zappa. Everithing works fine, exept css style.

I installed also 'django_s3_storage', 'storages', and add them to my app. Also I have the AWS settings:

S3_BUCKET = "<busket_name>"
STATICFILES_STORAGE = "django_s3_storage.storage.StaticS3Storage"
AWS_S3_BUCKET_NAME_STATIC = S3_BUCKET
STATIC_URL = "https://%s.s3.amazonaws.com/" % S3_BUCKET
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % S3_BUCKET
AWS_ACCESS_KEY_ID = config("SERVER_AWS_ACCESS_KEY_ID", '')
AWS_SECRET_ACCESS_KEY = config('SERVER_AWS_SECRET_ACCESS_KEY', '')
AWS_STORAGE_BUCKET_NAME = config('SERVER_AWS_STORAGE_BUCKET_NAME', '')
AWS_S3_REGION_NAME = 'us-east-1'

What is wrong? The admin page still without css: enter image description here


Solution

  • Set AWS Bucket's permissions: Set public permission and turn off 'Block all public access' Set bucket policy

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Principal": "*",
                "Action": [
                    "s3:PutObject",
                    "s3:PutObjectAcl",
                    "s3:GetObject",
                    "s3:GetObjectAcl",
                    "s3:DeleteObject"
                ],
                "Resource": [
                    "arn:aws:s3:::your_bucket_name",
                    "arn:aws:s3:::your_bucket_name/*"
                ]
            }
        ]
    }
    

    Bucket Ownership

    Permissions -> Ownership -> ACLs enabled 
    

    Run in terminal for collect static files

     python manage.py collectstatic
    

    Restart your terminal and deploy zappa again for changes to take effect.