---
# System prepended metadata

title: Django - Move Static file to S3
tags: [AWS, S3, Django]

---

# Django - Move Static file to S3
###### tags: `AWS`, `S3`, `Django`

## :memo: Where do I start?
### Step 1: Create a user who has perssion of S3 in IAM
* Create a User and chose accescc type to programmatic access
![](https://i.imgur.com/TS5QAdp.png)
* Create a group which has AmazonS3FullAccess
![](https://i.imgur.com/pX9q7EI.png)
* Click Create User bottom and and Download CSV
![](https://i.imgur.com/jklERJ7.png)


---

### Step 2: Create a S3

* Cancel Block all public access

![](https://i.imgur.com/YygDBV8.png)
* Set Public access, Everyone can read
![](https://i.imgur.com/ylWCHFk.png)

---

### Step 3: Install Package 

`pip install django-storages`

---
### Step 4: Edit Django Settings by CSV you downloaded before
```

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME', '')
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_DEFAULT_ACL = 'public-read'
```
---
### Step 5: Collect Static Files
`python manage.py collectstatic`

### Step 6: Check if it works
![](https://i.imgur.com/4uBVH2c.png)

