Unable to Upload Files to S3 from Django on Amazon Lightsail, Despite Working Fine Locally with Same Credentials and Policy

I'm running into an issue where I can successfully upload files to my S3 bucket locally, but I encounter problems when trying to upload from my server. Here are the details:

Django Settings

Settings.py (relevant parts):

STATIC_URL = "https://my-cdn.s3.amazonaws.com/static/"
STATICFILES_STORAGE = env("STATICFILES_STORAGE")

AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")
AWS_S3_REGION_NAME = env("AWS_S3_REGION_NAME")
DEFAULT_FILE_STORAGE = env("DEFAULT_FILE_STORAGE")
MEDIA_URL = env("MEDIA_URL")

S3 Policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-cdn/*"
        },
        {
            "Sid": "AllowPutObject",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::id:user/my-cdn"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::my-cdn/*"
        }
    ]
}

Issue:

  • Local Environment: Uploading files to the S3 bucket works perfectly.
  • Amazon Lightsail Server: Uploads fail (No logs whatsoever), but the credentials and policy are the same.
Back to Top