{"id":325,"date":"2026-11-21T12:00:00","date_gmt":"2026-11-21T12:00:00","guid":{"rendered":"https:\/\/rezachegini.com\/?p=325"},"modified":"2026-11-21T19:12:34","modified_gmt":"2026-11-21T19:12:34","slug":"building-a-job-board-api-part-23-one-setting-two-clouds-s3-or-azure-blob-storage","status":"publish","type":"post","link":"https:\/\/rezachegini.com\/?p=325","title":{"rendered":"Building a Job Board API, Part 23: One Setting, Two Clouds: S3 or Azure Blob Storage"},"content":{"rendered":"<p>I&#8217;m sharing one of my projects here from the beginning, step by step. It&#8217;s a Job Board API built with Django, Django REST Framework, PostgreSQL and Docker Compose, with S3 and SQS (through LocalStack), Redis, and a background worker.<\/p>\n<p>I&#8217;m a junior engineer looking for my first role in DevOps, SRE or Cloud. That&#8217;s why I build projects like this and write about them in public. It shows how I think, and writing it down helps me really understand it.<\/p>\n<p>Phase 6 makes the API run on two clouds. Until now, everything was AWS: resumes in S3, messages in SQS. In this phase, the same image must also run on Azure, and the choice must come from environment variables only. This part does the first half: storage.<\/p>\n<p>A new setting, CLOUD_PROVIDER, picks the storage backend:<\/p>\n<ul class=\"wp-block-list\">\n<li>aws (the default): S3, with S3 presigned download links, exactly as before.<\/li>\n<li>azure: Azure Blob Storage, with SAS links. Same 5-minute expiry, same download filename.<\/li>\n<\/ul>\n<p>Locally, Azure Blob Storage runs in Azurite, Microsoft&#8217;s Azure Storage emulator, the way S3 runs in LocalStack.<\/p>\n<p>The result: the same image, started with only -e CLOUD_PROVIDER=azure, stored a resume in Azurite and served a working SAS link that downloaded the PDF as resume-12.pdf. A link with a faked signature was rejected with 403. And an unknown provider stops the app at startup.<\/p>\n<p>The queue is still SQS for both providers. Moving that to Azure is the next step.<\/p>\n<h3 class=\"wp-block-heading\">The dependency<\/h3>\n<pre class=\"wp-block-code\"><code>uv add \"django-storages[azure,s3]\"<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Both extras in one image. s3 pulls in boto3, and azure pulls in azure-storage-blob. One image contains both, so switching clouds needs only an environment variable, not a different image.<\/li>\n<li>Why both in one command? uv add &#8220;django-storages[azure]&#8221; alone could rewrite the requirement without s3, and that would drop boto3 for the AWS path.<\/li>\n<li>It turned out the requirement was already locked with both extras, so uv reported nothing to change.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">Azurite in Docker Compose<\/h3>\n<pre class=\"wp-block-code\"><code>azurite:\n    image: mcr.microsoft.com\/azure-storage\/azurite:3.37.0\n    command: [\"azurite-blob\", \"--blobHost\", \"0.0.0.0\", \"--skipApiVersionCheck\"]\n    ports:\n      - \"127.0.0.1:10000:10000\"<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>Pinned to 3.37.0, the version the latest image reported. Same rule as LocalStack: builds shouldn&#8217;t change under me.<\/li>\n<li>azurite-blob runs only the Blob service. Azurite also emulates Queue and Table storage, which I don&#8217;t use. And careful: Azure Storage Queues are not Service Bus, which is what the next step uses.<\/li>\n<li>&#8211;blobHost 0.0.0.0 listens on all interfaces inside the container. The default, 127.0.0.1, would only accept connections from inside the Azurite container itself, so the API couldn&#8217;t reach it. Same idea as gunicorn&#8217;s bind address in Part 17.<\/li>\n<li>&#8211;skipApiVersionCheck: the Azure SDK sends an API version with every request, and Azurite rejects versions newer than it knows. The SDK updates more often than Azurite, so this avoids a mismatch.<\/li>\n<li>127.0.0.1:10000:10000: reachable from thor (for the download check), but not from the network.<\/li>\n<li>No volume. Blobs live inside the container and are lost when it&#8217;s recreated, like LocalStack&#8217;s S3.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">The provider switch<\/h3>\n<p>In config\/settings.py:<\/p>\n<pre class=\"wp-block-code\"><code>CLOUD_PROVIDER = env(\"CLOUD_PROVIDER\", \"aws\").strip().lower()\nif CLOUD_PROVIDER not in (\"aws\", \"azure\"):\n    raise ImproperlyConfigured(\n        f\"CLOUD_PROVIDER must be 'aws' or 'azure', not {CLOUD_PROVIDER!r}\"\n    )<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>The default is aws, so every existing environment keeps working without a new variable.<\/li>\n<li>.strip().lower() means Azure and aws work too.<\/li>\n<li>Fail fast on anything else. A typo like azrue would otherwise silently run the AWS path in an Azure deployment. That&#8217;s the same &#8220;fail fast&#8221; rule as Part 16. I tested it: -e CLOUD_PROVIDER=gcp stops with CLOUD_PROVIDER must be &#8216;aws&#8217; or &#8216;azure&#8217;, not &#8216;gcp&#8217;.<\/li>\n<li>!r shows the value with quotes (&#8216;gcp&#8217;), so an empty or space-padded value is visible in the error.<\/li>\n<\/ul>\n<p>The shared settings stay above the if. Both providers use the 5-minute link expiry and the 60-second cache time. And SQS stays outside the if for now, because the API and the worker still publish to SQS whatever provider is chosen. The next step moves it into the AWS branch.<\/p>\n<h3 class=\"wp-block-heading\">The AWS branch<\/h3>\n<pre class=\"wp-block-code\"><code>if CLOUD_PROVIDER == \"aws\":\n    AWS_STORAGE_BUCKET_NAME = env(\"AWS_STORAGE_BUCKET_NAME\")\n    AWS_S3_REGION_NAME = AWS_REGION\n    AWS_S3_ENDPOINT_URL = env(\"AWS_S3_ENDPOINT_URL\", \"\") or None\n    AWS_S3_PUBLIC_ENDPOINT_URL = (\n        env(\"AWS_S3_PUBLIC_ENDPOINT_URL\", \"\") or AWS_S3_ENDPOINT_URL\n    )\n    AWS_DEFAULT_ACL = None\n    AWS_S3_FILE_OVERWRITE = False\n    AWS_QUERYSTRING_AUTH = True\n    DEFAULT_STORAGE_BACKEND = \"storages.backends.s3.S3Storage\"<\/code><\/pre>\n<p>The same S3 settings as before, now inside the branch. The bucket name is required only for AWS. An Azure deployment doesn&#8217;t have to invent a fake bucket name just to start. DEFAULT_STORAGE_BACKEND is a plain variable that each branch sets, used once below.<\/p>\n<h3 class=\"wp-block-heading\">The Azure branch<\/h3>\n<pre class=\"wp-block-code\"><code>else:\n    AZURE_ACCOUNT_NAME = env(\"AZURE_ACCOUNT_NAME\")\n    AZURE_ACCOUNT_KEY = env(\"AZURE_ACCOUNT_KEY\")\n    AZURE_CONTAINER = env(\"AZURE_CONTAINER\")<\/code><\/pre>\n<p>These are the names django-storages&#8217; AzureStorage reads, and the environment variables use the same names, like the AWS_* ones. All three are required: the storage account, its key (to sign SAS links) and the container (Azure&#8217;s word for a bucket).<\/p>\n<pre class=\"wp-block-code\"><code>    AZURE_BLOB_ENDPOINT = (\n        env(\"AZURE_BLOB_ENDPOINT\", \"\")\n        or f\"https:\/\/{AZURE_ACCOUNT_NAME}.blob.core.windows.net\"\n    )\n    AZURE_PUBLIC_BLOB_ENDPOINT = (\n        env(\"AZURE_PUBLIC_BLOB_ENDPOINT\", \"\") or AZURE_BLOB_ENDPOINT\n    )<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>No endpoint means real Azure. Every Azure storage account lives at https:\/\/&lt;account&gt;.blob.core.windows.net. That mirrors &#8220;no AWS_S3_ENDPOINT_URL means real S3&#8221;.<\/li>\n<li>Azurite puts the account name in the path, like http:\/\/azurite:10000\/devstoreaccount1, because one emulator serves any account. Real Azure puts it in the host name. Building every URL from this one setting handles both.<\/li>\n<li>The public endpoint defaults to the internal one. On real Azure they&#8217;re the same address. Locally they&#8217;re different: the API reaches azurite, and a browser reaches localhost. It&#8217;s the same internal-vs-public problem I solved for S3 in Part 7.<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code>    AZURE_CONNECTION_STRING = (\n        f\"DefaultEndpointsProtocol={AZURE_BLOB_ENDPOINT.split(':\/\/')[0]};\"\n        f\"AccountName={AZURE_ACCOUNT_NAME};AccountKey={AZURE_ACCOUNT_KEY};\"\n        f\"BlobEndpoint={AZURE_BLOB_ENDPOINT};\"\n    )<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>A connection string is Azure&#8217;s single-string client configuration, made of Key=Value; pairs. django-storages uses it to build its client, and it&#8217;s the way to point the SDK at a custom endpoint like Azurite.<\/li>\n<li>I build it here from the parts, so .env never holds one long string with the key hidden inside it.<\/li>\n<li>split(&#8216;:\/\/&#8217;)[0] takes http or https from the endpoint, so Azurite (http) and real Azure (https) both work.<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code>    AZURE_OVERWRITE_FILES = False\n    DEFAULT_STORAGE_BACKEND = \"storages.backends.azure_storage.AzureStorage\"<\/code><\/pre>\n<p>The same rule as AWS_S3_FILE_OVERWRITE = False: never silently replace an existing file.<\/p>\n<h3 class=\"wp-block-heading\">STORAGES: no model changes<\/h3>\n<pre class=\"wp-block-code\"><code>STORAGES = {\n    \"default\": {\"BACKEND\": DEFAULT_STORAGE_BACKEND},\n    \"staticfiles\": {\"BACKEND\": \"django.contrib.staticfiles.storage.StaticFilesStorage\"},\n}<\/code><\/pre>\n<p>default is the storage that every FileField uses, including Application.resume. So no model code changes at all. That&#8217;s the whole point of going through django-storages: the models and views don&#8217;t know which cloud they&#8217;re on.<\/p>\n<h3 class=\"wp-block-heading\">Quieter Azure SDK logs<\/h3>\n<p>The first Azure run filled the logs. The Azure SDK has a logger, azure.core.pipeline.policies.http_logging_policy, that writes two INFO lines for every HTTP call: the request&#8217;s URL, method and headers, then the response&#8217;s status and headers.<\/p>\n<p>The SDK redacts secrets (&#8216;Authorization&#8217;: &#8216;REDACTED&#8217;), so nothing leaked. The problem was volume: two big lines per upload, per download link and per readiness check. One line fixed it, in the LOGGING setting from Part 15:<\/p>\n<pre class=\"wp-block-code\"><code>\"azure\": {\"level\": \"WARNING\"},<\/code><\/pre>\n<p>azure is the parent of every Azure SDK logger (azure.core&#8230;, azure.storage&#8230;). Loggers inherit their level from the nearest configured parent, so this one entry covers them all. It has no handler of its own, so its warnings and errors still travel up to root as JSON. That&#8217;s the same rule I used for botocore.<\/p>\n<h3 class=\"wp-block-heading\">The .env file<\/h3>\n<pre class=\"wp-block-code\"><code># Cloud provider: aws (default) or azure\nCLOUD_PROVIDER=aws\n\n# Azure Storage (used when CLOUD_PROVIDER=azure). Azurite's well-known development account,\n# published by Microsoft, not a secret. On real Azure: your account, key from a secret store, no endpoint URLs.\nAZURE_ACCOUNT_NAME=devstoreaccount1\nAZURE_ACCOUNT_KEY=Eby8vdM02x...GMGw==\nAZURE_CONTAINER=resumes\nAZURE_BLOB_ENDPOINT=http:\/\/azurite:10000\/devstoreaccount1\nAZURE_PUBLIC_BLOB_ENDPOINT=http:\/\/localhost:10000\/devstoreaccount1<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>That Azurite key is not a secret. It&#8217;s Microsoft&#8217;s published development key, like LocalStack&#8217;s test\/test. A real account key is a secret, and it never goes in a file.<\/li>\n<li>CLOUD_PROVIDER=aws stays in .env. The Azure values sit there unused until a container starts with -e CLOUD_PROVIDER=azure. That&#8217;s how one .env can run either cloud.<\/li>\n<li>I added them to my real .env with sed -n &#8216;\/^# Cloud provider\/,$p&#8217; .env.example &gt;&gt; .env, which prints from the # Cloud provider line to the end of the file. A grep -q &#8230; || guard in front prevents duplicates.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">storage.py: the only cloud-specific code outside settings<\/h3>\n<pre class=\"wp-block-code\"><code>def resume_download_url(application):\n    if settings.CLOUD_PROVIDER == \"azure\":\n        return _azure_download_url(application)\n    return _s3_download_url(application)<\/code><\/pre>\n<p>The resume view calls resume_download_url exactly as before. It doesn&#8217;t know which cloud it&#8217;s on.<\/p>\n<p>Why not just use application.resume.url? Both django-storages backends can sign URLs. But they sign with the internal endpoint (localstack or azurite), which a browser can&#8217;t reach. Signing the links myself lets me use the public endpoint, and set the download filename, in the same way for both clouds.<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1479\" height=\"605\" src=\"http:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-23-diagram.png\" alt=\"Diagram: GET resume endpoint calls resume_download_url, which branches on CLOUD_PROVIDER to an S3 presigned URL or an Azure SAS URL; both are public links with a 5-minute expiry, downloading as resume-12.pdf\" class=\"wp-image-324\" srcset=\"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-23-diagram.png 1479w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-23-diagram-300x123.png 300w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-23-diagram-1024x419.png 1024w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-23-diagram-768x314.png 768w\" sizes=\"auto, (max-width: 1479px) 100vw, 1479px\" \/><\/figure>\n<pre class=\"wp-block-code\"><code>def _download_filename(application):\n    return f\"resume-{application.id}{Path(application.resume.name).suffix}\"<\/code><\/pre>\n<p>Shared by both clouds: the file downloads as resume-12.pdf, never as the random storage key or the candidate&#8217;s original filename.<\/p>\n<p>The S3 function didn&#8217;t change. It&#8217;s the same generate_presigned_url code from Part 7, now using the shared filename helper, and the moto tests from Part 20 still check its path, expiry, signature and filename.<\/p>\n<h3 class=\"wp-block-heading\">The Azure SAS link<\/h3>\n<p>A SAS (Shared Access Signature) is Azure&#8217;s version of a presigned URL: a link that carries its own permission, scope and expiry, signed so nobody can change them.<\/p>\n<pre class=\"wp-block-code\"><code>def _azure_download_url(application):\n    name = application.resume.name\n    sas = generate_blob_sas(\n        account_name=settings.AZURE_ACCOUNT_NAME,\n        container_name=settings.AZURE_CONTAINER,\n        blob_name=name,\n        account_key=settings.AZURE_ACCOUNT_KEY,\n        permission=BlobSasPermissions(read=True),\n        expiry=datetime.now(timezone.utc) + timedelta(seconds=settings.RESUME_URL_EXPIRE_SECONDS),\n        content_disposition=f'attachment; filename=\"{_download_filename(application)}\"',\n    )\n    return f\"{settings.AZURE_PUBLIC_BLOB_ENDPOINT}\/{settings.AZURE_CONTAINER}\/{quote(name)}?{sas}\"<\/code><\/pre>\n<ul class=\"wp-block-list\">\n<li>generate_blob_sas computes the signature locally, with no network call, just like boto3&#8217;s presigning.<\/li>\n<li>The scope, line by line: one blob: the container plus the blob name; read only: BlobSasPermissions(read=True), so no write, no delete, no list; 5 minutes: expiry, an aware UTC datetime; the download filename: content_disposition makes Azure send Content-Disposition: attachment; filename=&#8221;resume-12.pdf&#8221; with the file.<\/li>\n<li>quote(name) URL-encodes the blob path, but keeps the \/.<\/li>\n<li>Locally, the link looks like http:\/\/localhost:10000\/devstoreaccount1\/resumes\/resume\/job-1\/&lt;hex&gt;.pdf?se=&#8230;&amp;sp=r&amp;&#8230;&amp;rscd=attachment&#8230;&amp;sig=&#8230;. sp=r is the read permission, se the expiry, rscd the content disposition, and sig the signature.<\/li>\n<\/ul>\n<p>It&#8217;s signed with the account key for now. That key gives access to the whole storage account. On real Azure, the better option is a user delegation key, obtained with a managed identity (Workload Identity on AKS). Then no account key exists in the app&#8217;s environment at all. That&#8217;s for my next project&#8217;s Azure phase.<\/p>\n<h3 class=\"wp-block-heading\">How I tested it<\/h3>\n<ol class=\"wp-block-list\">\n<li>The stack runs. After a rebuild, azurite:3.37.0 was pulled and docker compose ps azurite showed it Up on 127.0.0.1:10000.<\/li>\n<li>The env file is complete. grep -c counted 6 Azure and provider lines in both .env and .env.example, and 0 quoted values. As in Part 16, quotes would break docker run &#8211;env-file.<\/li>\n<li>The default didn&#8217;t change, and a typo fails. The dev API printed aws and S3Storage. With -e CLOUD_PROVIDER=gcp, startup stopped with CLOUD_PROVIDER must be &#8216;aws&#8217; or &#8216;azure&#8217;, not &#8216;gcp&#8217;.<\/li>\n<li>One variable switches the cloud. The same image, started with -e CLOUD_PROVIDER=azure on port 8017, was up after 2 seconds, and printed azure and AzureStorage.<\/li>\n<li>The container exists. Creating the resumes container returned 409 ContainerAlreadyExists on the rerun, because the first run had created it, and listing showed [&#8216;resumes&#8217;].<\/li>\n<li>Upload works. Saving riya&#8217;s resume through the Azure backend: a HEAD returned 404, then the PUT returned 201, then a HEAD returned 200 with content-length: 27 and content-type: application\/pdf. The stored file was resume\/job-1\/4af3&#8230;pdf, 27 bytes, through AzureStorage.<\/li>\n<li>The SAS link really works, and is really signed. The link from the Azure API used the public endpoint (http:\/\/localhost:10000\/&#8230;). Downloading it on thor returned 200, with content-disposition: attachment; filename=&#8221;resume-12.pdf&#8221;, and the body started with %PDF-1.4. Then I changed the signature, and Azurite returned 403. A test that only checks the happy path can&#8217;t tell a signed link from an open one. The 403 is the proof.<\/li>\n<li>The SDK noise is gone. After the logging fix, an Azure SDK call produced 0 http_logging_policy lines. Before, it was 2 per call.<\/li>\n<li>Back to AWS. I removed the Azure container, re-saved the resume through the normal AWS API, and it was stored as resume\/job-1\/bb1c&#8230;pdf through S3Storage.<\/li>\n<li>The test suite: 203 passed, but coverage is now 98.17%. The uncovered lines are exactly the new Azure code: settings.py lines 35 and 60 to 76, and storage.py lines 14 and 45 to 55. The AWS path is unchanged, and the Azure lines get tests in a later step. It&#8217;s still well above the 80% gate from Part 21.<\/li>\n<\/ol>\n<p>These commands repeat the main checks:<\/p>\n<pre class=\"wp-block-code\"><code>docker run --rm --env-file .env -e CLOUD_PROVIDER=gcp 00-job-board-api-api python manage.py check 2&gt;&amp;1 | tail -n 1   # CLOUD_PROVIDER must be ...\ndocker run -d --name jb-azure --network 00-job-board-api_default --env-file .env -e CLOUD_PROVIDER=azure -p 127.0.0.1:8017:8006 00-job-board-api-api\ndocker exec jb-azure python manage.py shell -c \"from django.conf import settings as s; print(s.CLOUD_PROVIDER, s.STORAGES['default'])\"   # azure ... AzureStorage\ndocker rm -f jb-azure<\/code><\/pre>\n<p>One thing to remember about these checks: both clouds shared one database. So switching the provider changed which store an application&#8217;s resume path pointed to. A real deployment has one cloud per database.<\/p>\n<h3 class=\"wp-block-heading\">Problems I hit<\/h3>\n<p>This step had more problems than usual, and almost all of them were about how I ran commands, not the code.<\/p>\n<h3 class=\"wp-block-heading\">1. The file wasn&#8217;t replaced<\/h3>\n<p>My check, grep -n &#8220;^from azure\\|^def _azure_download_url\\|^def resume_download_url&#8221; jobs\/storage.py, found only resume_download_url on line 19. That meant the old file was still there. I wrote the file again with a heredoc (cat &gt; jobs\/storage.py &lt;&lt;&#8216;EOF&#8217;), and the grep then found lines 7, 12 and 44.<\/p>\n<h3 class=\"wp-block-heading\">2. An image tag that was literally a placeholder<\/h3>\n<p>The Azurite image was :&lt;version-from-above&gt;. A snippet I was following used a placeholder for the version, and I copied it exactly as written. I found it with docker compose config | grep -E &#8220;image:&#8221;. My first try with -A4 missed it, because docker compose config sorts keys alphabetically, so the image line wasn&#8217;t where I expected. Fixed with sed to :3.37.0.<\/p>\n<h3 class=\"wp-block-heading\">3. The Azure variables weren&#8217;t in .env<\/h3>\n<p>grep -c returned 0. I added them with the guarded sed -n &#8230; &gt;&gt; .env block, and the counts became 6 and 6.<\/p>\n<h3 class=\"wp-block-heading\">4. Bash showed &gt; and waited<\/h3>\n<p>After pasting a heredoc, bash showed &gt; and seemed to be asking for something. It wasn&#8217;t asking anything. &gt; is bash&#8217;s continuation prompt: bash thinks the command isn&#8217;t finished. A heredoc (&lt;&lt;&#8216;EOF&#8217;) stays open until bash reads a line that is exactly EOF. If that line arrives with spaces around it, or merged with the next line, bash keeps waiting. The fix: type EOF alone and press Enter, or press Ctrl+C and paste again.<\/p>\n<h3 class=\"wp-block-heading\">5. A rerun that looked broken, and stale files that looked fine<\/h3>\n<p>I reran checks 3 to 7 and got No such container: jb-azure three times, a JSONDecodeError, curl: blank argument, and tampered 000. The cause: my first paste had already run check 9, docker rm -f jb-azure, so the container was gone.<\/p>\n<p>The tricky part was the other lines in the rerun. The content-disposition and %PDF-1.4 lines looked correct. But they came from old output files (\/tmp\/h.txt and \/tmp\/r.pdf) left over from the first run. A failing rerun printed old success. The real results are the first run&#8217;s, including the tampered 403.<\/p>\n<p><strong>The lesson:<\/strong> delete a check&#8217;s output files before the check writes them. Otherwise a failed run can look like a passed one.<\/p>\n<h3 class=\"wp-block-heading\">6. The SDK&#8217;s log noise<\/h3>\n<p>Explained above: two large INFO lines per HTTP call, fixed with &#8220;azure&#8221;: {&#8220;level&#8221;: &#8220;WARNING&#8221;}. One detail: the image has to be rebuilt before a container started from it sees the new setting.<\/p>\n<h3 class=\"wp-block-heading\">7. A finding: the old file stays behind<\/h3>\n<p>After the second run, Azurite had two blobs: 4af3&#8230; and aad5&#8230;, 27 bytes each. The second one was the first run&#8217;s file, never deleted.<\/p>\n<p>When you save a new file on application.resume, the row points to a new key, and Django&#8217;s FileField never deletes the old file. It&#8217;s the same kind of leftover as the orphaned file from the duplicate race in Part 20. Cleaning it up (deleting the old file on replace, or a sweep for orphans) is a decision for later.<\/p>\n<h3 class=\"wp-block-heading\">AWS vs Azure: the real differences<\/h3>\n<ul class=\"wp-block-list\">\n<li>The extra level. S3 has a bucket. Azure has a storage account, then a container, then the blob. The account is in every URL, and it owns the key.<\/li>\n<li>The same interface. S3Storage and AzureStorage both plug into django-storages, so the models didn&#8217;t change.<\/li>\n<li>Presigned URL vs SAS. S3 links carry X-Amz-* parameters and a SigV4 signature. SAS links carry sv, se, sp, sig and others. Both are signed locally. But S3 signs with IAM credentials, while my SAS signs with the account key, one key for the whole account.<\/li>\n<li>The download filename. ResponseContentDisposition in S3, content_disposition (rscd) in Azure. Same effect.<\/li>\n<li>The emulators. LocalStack uses test\/test. Azurite uses devstoreaccount1 and a published key. Both are public development credentials.<\/li>\n<li>The default address. No endpoint means s3.amazonaws.com for AWS, and &lt;account&gt;.blob.core.windows.net for Azure. The Azure address depends on the account name.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">Why I chose this way<\/h3>\n<ul class=\"wp-block-list\">\n<li>A validated CLOUD_PROVIDER with aws as the default. Existing environments don&#8217;t change, and typos fail fast instead of silently falling back to AWS.<\/li>\n<li>Each cloud&#8217;s settings are required only for that cloud. No fake values for the other cloud.<\/li>\n<li>I sign the links myself for both clouds. The public endpoint and the download filename behave the same way. resume.url would sign with the internal host.<\/li>\n<li>The connection string is built from parts. One key variable, and no long string with a secret hidden inside.<\/li>\n<li>An account-key SAS for now. It works with Azurite and has the same shape as on real Azure. A user delegation SAS with a managed identity comes later.<\/li>\n<li>Both SDKs in one image. That&#8217;s the phase goal: switch clouds with environment variables only, not with separate images.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">What I learned<\/h3>\n<ul class=\"wp-block-list\">\n<li>One validated setting can switch the cloud, with each cloud&#8217;s settings required only when it&#8217;s chosen.<\/li>\n<li>django-storages is the portability layer. Models and views don&#8217;t know which cloud they&#8217;re on.<\/li>\n<li>Azure Blob Storage has three levels: account, container, blob. And the endpoint depends on the account.<\/li>\n<li>A SAS is Azure&#8217;s presigned URL: scoped, expiring and signed.<\/li>\n<li>Emulators use published credentials. A real account key never goes in a file.<\/li>\n<li>Internal and public endpoints are different, again. The API talks to azurite, the browser to localhost.<\/li>\n<li>A tampered link must fail. A 403 proves the signature is real.<\/li>\n<li>Old output files can make a failed check look like a passed one. Delete them first.<\/li>\n<li>&gt; in bash is a continuation prompt, not a question.<\/li>\n<li>Django&#8217;s FileField never deletes the old file when you save a new one.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">What comes next<\/h3>\n<p>This completes the first item of Phase 6: storage switches between S3 and Azure Blob Storage. But the queue is still SQS, whichever cloud is chosen. The next step moves it too: on Azure, messages will go through Azure Service Bus, behind the same queue interface the worker already uses.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m sharing one of my projects here from the beginning, step by step. It&#8217;s a Job Board API built with Django, Django&hellip;<\/p>\n","protected":false},"author":2,"featured_media":323,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_rezaops_part":"23","_rezaops_linkedin_url":"https:\/\/www.linkedin.com\/pulse\/building-job-board-api-part-23-one-setting-two-clouds-reza-chegini-ob7ec\/","footnotes":""},"categories":[85,50,10,116],"tags":[60,52,219,8,111,191,118,25,112,193],"series":[117],"class_list":["post-325","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-azure","category-devops","category-django","tag-aws","tag-azure","tag-azure-blob-storage","tag-devops","tag-django","tag-drf","tag-job-board","tag-python","tag-rest-api","tag-s3","series-job-board-api"],"jetpack_featured_media_url":"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/11\/job-board-api-part-23-cover.png","_links":{"self":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325"}],"version-history":[{"count":1,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/325\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/325\/revisions\/326"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/media\/323"}],"wp:attachment":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}