SKILL·4ED528

django-storages-s3

jeffallan
更新于 3 days ago
10,969
1,029
10,969
在 GitHub 上查看
测试testing

关于

This Claude Skill helps developers configure Django to store static and media files on AWS S3 using the django-storages package. It provides expert guidance for setting up the STORAGES dictionary, creating custom backends, generating presigned URLs, and integrating with CloudFront. Use it when implementing S3-backed file storage, managing IAM policies, or mocking S3 for tests in your Django settings.

快速安装

Claude Code

推荐
主要方式
npx skills add jeffallan/claude-skills -a claude-code
插件命令备选方式
/plugin add https://github.com/jeffallan/claude-skills
Git 克隆备选方式
git clone https://github.com/jeffallan/claude-skills.git ~/.claude/skills/django-storages-s3

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Django Storages S3

Senior Django specialist for production-grade file storage on AWS S3 via django-storages and boto3 — public and private media, static files, presigned URLs, and CloudFront.

When to Use This Skill

  • Serving static and/or media files from AWS S3 instead of the local filesystem
  • Configuring the Django 4.2+ STORAGES dict or legacy DEFAULT_FILE_STORAGE
  • Separating public (CDN-served) and private (presigned) file backends
  • Generating presigned download or direct browser-to-S3 upload URLs
  • Fronting S3 with CloudFront and writing a least-privilege IAM policy
  • Migrating local FileField/ImageField storage to S3 without code changes
  • Testing storage code without hitting S3

Core Workflow

  1. Install & registerpip install django-storages[s3] boto3; add "storages" to INSTALLED_APPS
  2. Configure credentials — Load from env vars or rely on an attached IAM role; never hardcode
  3. Wire the STORAGES dict — Set default (media) and staticfiles backends with separate location prefixes
  4. Add named backends — Split public vs. private buckets/ACLs as additional STORAGES entries when needed
  5. Verify & test — Run collectstatic, confirm uploads land in S3, and mock S3 in tests with InMemoryStorage or moto

Reference Guide

Load detailed guidance based on context:

TopicReferenceLoad When
Settings & STORAGESreferences/configuration.mdCore settings, 4.2+ vs legacy, CloudFront
Custom backendsreferences/custom-backends.mdPublic vs. private buckets, per-field storage
Presigned URLsreferences/presigned-urls.mdDownload links, direct browser uploads
Testing & IAMreferences/testing-storages.mdMocking S3, IAM policy, common pitfalls

Minimal Working Example

The snippet below demonstrates the core MUST DO constraints: env-loaded credentials, STORAGES dict, separate media/static locations, and default_acl=None on the media backend.

# settings.py
import os

AWS_STORAGE_BUCKET_NAME = os.environ["AWS_STORAGE_BUCKET_NAME"]
AWS_S3_REGION_NAME = os.environ.get("AWS_S3_REGION_NAME", "us-east-1")
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_S3_REGION_NAME}.amazonaws.com"
# On EC2/ECS/Lambda, omit keys entirely — boto3 uses the attached IAM role.

STORAGES = {
    "default": {  # media uploads
        "BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
        "OPTIONS": {
            "bucket_name": AWS_STORAGE_BUCKET_NAME,
            "location": "media",
            "default_acl": None,        # rely on bucket policy, not per-object ACLs
            "file_overwrite": False,
            "querystring_auth": False,  # public objects → clean URLs
        },
    },
    "staticfiles": {
        "BACKEND": "storages.backends.s3boto3.S3StaticStorage",
        "OPTIONS": {
            "bucket_name": AWS_STORAGE_BUCKET_NAME,
            "location": "static",
        },
    },
}

MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/media/"
STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/static/"
# models.py — uploads go straight to S3 on save()
from django.db import models

class Document(models.Model):
    file = models.FileField(upload_to="docs/")  # uses STORAGES["default"]

Auditing an Existing Configuration

When reviewing a project that already uses S3 (not greenfield), walk this checklist — each item is a constraint below rephrased as "find X, confirm Y":

  1. Credentialsgrep -rn "AWS_SECRET_ACCESS_KEY\|aws_secret" settings/ → confirm values come from os.environ/django-environ or an IAM role, never literals committed to the repo.
  2. ACLsgrep -rn "default_acl\|AWS_DEFAULT_ACL" . → on buckets created after April 2023, every value must be None. Any "public-read"/"private" will raise AccessControlListNotSupported; public access belongs in a bucket policy.
  3. Storage backend — confirm Django 4.2+ uses the STORAGES dict, not DEFAULT_FILE_STORAGE/STATICFILES_STORAGE (removed in Django 5.1, so silently ignored on 5.1/5.2/6.0); confirm the static class is S3StaticStorage, not a fabricated name.
  4. Locations — confirm default (media) and staticfiles have distinct location prefixes or buckets so collectstatic never collides with uploads.
  5. Region — confirm region_name (or the global AWS_S3_REGION_NAME) matches the bucket's real region and that AWS_S3_CUSTOM_DOMAIN includes the region segment for non-us-east-1 buckets.
  6. Presigning — for private backends, confirm querystring_auth=True and custom_domain=None; confirm presigned .url() results aren't cached past AWS_QUERYSTRING_EXPIRE.
  7. Overwrite cleanup — where file_overwrite=False, confirm replaced files are explicitly deleted (otherwise superseded objects leak).
  8. IAM — confirm the policy grants only Get/Put/Delete/ListBucket on the bucket ARN, not broader S3 access.

Constraints

MUST DO

  • Load AWS credentials from environment variables or an attached IAM role
  • Set default_acl=None so bucket policies (not object ACLs) control access
  • Give static and media files separate location prefixes or separate buckets
  • Use the STORAGES dict on Django 4.2+ (same config through 5.2 LTS and 6.0); DEFAULT_FILE_STORAGE/STATICFILES_STORAGE were removed in 5.1, so reserve them for < 4.2 only
  • Set custom_domain=None on any backend that issues presigned URLs
  • Mock S3 (InMemoryStorage or moto) in tests instead of hitting real buckets

MUST NOT DO

  • Hardcode AWS_SECRET_ACCESS_KEY in settings.py or commit it
  • Mix querystring_auth=True with a custom_domain (presigning breaks)
  • Mix static and media files under the same prefix
  • Grant the IAM user broader than Get/Put/Delete/ListBucket on the bucket ARN
  • Rely on per-object ACLs on buckets created after April 2023 (ACLs disabled by default)

Knowledge Reference

django-storages, S3Boto3Storage, S3StaticStorage, boto3, STORAGES dict, presigned URLs, generate_presigned_post, CloudFront, IAM policy, InMemoryStorage, moto

Related Skills

  • django-expert — core Django models, DRF, and ORM that produce the files this skill persists to S3
  • fullstack-guardian — secure end-to-end upload flows and access control around stored files
  • devops-engineer — provisioning the S3 buckets, IAM roles, and CloudFront distributions this skill targets

Documentation

GitHub 仓库

jeffallan/claude-skills
路径: skills/django-storages-s3
0
ai-agentsclaudeclaude-codeclaude-marketplaceclaude-skills
FAQ

常见问题

什么是 django-storages-s3 Skill?

django-storages-s3 是一个 Claude Skill,作者为 jeffallan。Skill 将 Claude 按需加载的说明和资源打包,让 Claude 无需额外提示即可执行与 django-storages-s3 相关的任务。

如何安装 django-storages-s3?

使用本页的安装命令:将 django-storages-s3 作为插件添加到 Claude Code,或将其仓库克隆到 skills 目录,然后重启 Claude 以加载该 Skill。

django-storages-s3 属于哪个分类?

django-storages-s3 属于测试分类。

django-storages-s3 可以免费使用吗?

可以。django-storages-s3 已收录在 AIMCP,可免费安装。

相关推荐技能

evaluating-llms-harness
测试

该Skill通过60+个学术基准测试(如MMLU、GSM8K等)评估大语言模型质量,适用于模型对比、学术研究及训练进度追踪。它支持HuggingFace、vLLM和API接口,被EleutherAI等行业领先机构广泛采用。开发者可通过简单命令行快速对模型进行多任务批量评估。

查看技能
cloudflare-cron-triggers
测试

这个Claude Skill提供了关于Cloudflare Cron Triggers的完整知识库,用于通过cron表达式定时执行Workers。它支持配置周期性任务、维护作业和自动化工作流,并能处理常见的cron触发错误。开发者可以用它来设置定时任务、测试cron处理器,并集成Workflows和Green Compute功能。

查看技能
webapp-testing
测试

该Skill为开发者提供了基于Playwright的本地Web应用测试工具集,支持自动化测试前端功能、调试UI行为、捕获屏幕截图和查看浏览器日志。它包含管理服务器生命周期的辅助脚本,可直接作为黑盒工具运行而无需阅读源码。适用于需要快速验证本地Web应用界面和交互功能的开发场景。

查看技能
finishing-a-development-branch
测试

这个Skill用于开发分支完成后的集成决策,当代码实现完成且测试通过时,它会引导开发者选择合适的工作流。它首先验证测试状态,然后提供合并、创建PR或清理等结构化选项。核心价值在于确保代码质量的同时,标准化分支收尾流程。

查看技能