Having bought a domain is not the same as having a website. Between typing awssinmapa.com in the browser and seeing a page with a padlock there are several pieces that have to fit together: someone has to answer where the site lives, someone has to store the files, someone has to deliver them fast and encrypted, and someone has to update them every time you change something.
In this article I put those pieces together on AWS exactly as I did for awssinmapa.com: the domain stays at GoDaddy, DNS moves to Amazon Route 53, the files live in an Amazon S3 bucket with no public access, Amazon CloudFront delivers them with an AWS Certificate Manager (ACM) certificate, and GitHub Actions publishes every change without long-lived AWS keys stored in GitHub. The initial setup was done from the console; since then, GitHub Actions handles the publishing. The bucket and the certificate are in us-east-1; Route 53 and CloudFront are global services.
It isn’t just the happy path. Along the way, four errors showed up that cost us time: an AccessDenied that wasn’t about permissions, a duplicated subdomain, an OIDC trust policy that didn’t match what GitHub was sending and a function that brought down the entire website. I explain them in diagnostic boxes, with the cause and the fix.
The architecture in one picture

There are two paths. The top one is the visitor’s: Route 53 resolves the name, CloudFront delivers the content over HTTPS and is the way into the bucket, which has no public access. The bottom one is the publishing path: every push builds the site and uploads it with credentials that last minutes. The rest of the article walks through each piece in that order.
The domain stays at GoDaddy; DNS moves to Route 53
A domain has two responsibilities that are often confused. The registrar holds ownership of the name: it’s the deed to the house. The DNS service answers which address that name points to: it’s the map to get there. They don’t have to be in the same place, and for this project there was no need to transfer the domain to AWS, only the DNS.
In Route 53 this is done with a public hosted zone, not with the options to register or transfer a domain:
- Route 53 → Create hosted zone, name
awssinmapa.com, type public hosted zone. - Route 53 creates the zone with two records:
SOAandNS. TheNSrecord comes with four AWS name servers. - At GoDaddy, in the domain’s DNS settings, the name servers are replaced with those four, using the option to use your own name servers.
GoDaddy warns that the records it had are not copied over. On a freshly bought domain there were only the “parked domain” ones, so there was nothing to migrate. If your domain already has email or subdomains, you first have to recreate those records in the Route 53 zone.
The change isn’t instant around the world: each DNS server keeps a temporary copy of the answers and renews it when it expires. In this case, a public DNS checker showed the new servers in every region after five minutes, but it can take longer. A useful detail for later: the browser error DNS_PROBE_FINISHED_NXDOMAIN means the name doesn’t resolve yet, either because records are missing or because your computer cached the “doesn’t exist” answer. It’s a DNS problem, not a website problem.
From the very first resource it’s worth tagging everything the same way. Here Proyecto = awssinmapa-web (Proyecto means “Project”) was used on the zone, the bucket and the distribution, to identify everything that belongs to the website. To analyze costs by that tag on the bill there is one more step: activating it as a cost allocation tag in the billing console (in an organization, from the management account). Activating this tag for cost allocation is still pending confirmation.
A private bucket for a public website
Many tutorials still teach you to make the bucket public and turn on S3 static website hosting. It works, but it leaves the storage open to anyone who guesses the bucket URL. Here the opposite pattern was followed: the bucket has no public access and visitors reach the files through CloudFront, which reads the bucket with Origin Access Control (OAC). Visitors come in through the store, not through the warehouse.
The awssinmapa-web bucket was created in us-east-1 as a general purpose bucket with this configuration:
| Option | Value | Why |
|---|---|---|
| Object Ownership | ACLs disabled | Permissions are handled only with policies |
| Block all public access | On | No public access; visitors arrive through CloudFront with OAC |
| Versioning | Enabled | Every replacement or deletion leaves a recoverable previous version |
| Encryption | SSE-S3 | Encryption at rest managed by S3 |
| Object Lock | Off | Object Lock protects existing versions against deletion or overwriting, something this website doesn’t need; once enabled, it can’t be turned off |
| Tag | Proyecto = awssinmapa-web |
Identifies the website’s resources |
Versioning seems like a luxury for a static website, but later it saved a file: the first automated publish deleted a video that had been uploaded by hand, and it remained as a previous version.
For the first page it was enough to upload index.html, 404.html and an img/ folder from the console. That “enough” has a catch, and it shows up in the CloudFront section.
HTTPS with ACM: why us-east-1 and why two names
The certificate is what makes the padlock possible: it proves the site belongs to who it says it does and encrypts the connection. ACM issues public certificates at no cost for use with services like CloudFront, with one condition that confuses a lot of people: CloudFront only accepts ACM certificates created in us-east-1, no matter which Region the rest is in. If you create it in another Region, it simply doesn’t appear in the list when you configure the distribution.
The request was made like this:
- Names:
awssinmapa.comand*.awssinmapa.com. The wildcard coverswwwand any future subdomain, but it doesn’t cover the bare domain. That’s why both are included. - Validation: DNS. ACM asks you to create a
CNAMErecord that only the domain owner can write, like the code your bank sends to your phone. Since the zone was already in Route 53, the “Create records in Route 53” button creates it for you, and a singleCNAMEvalidates both names. - Algorithm: RSA 2048.
- Export: off. An exportable certificate has a cost, and here there’s no need to take it out of AWS.
The status went from “Pending validation” to “Issued” in about six minutes. ACM automatically renews a DNS-validated certificate as long as it’s still in use by an integrated service, such as CloudFront, and the validation CNAME stays in the zone: you shouldn’t delete it.
CloudFront: the only way in
CloudFront is AWS’s content delivery network (CDN): it keeps copies of your files in locations around the world and serves them from the one closest to the visitor. In this architecture it also plays another role: it’s the path visitors take to reach the bucket, which has no public access.
Choosing a plan
When you create the distribution, the console now starts by asking about a plan. Besides the usual pay-as-you-go billing, there are flat-rate pricing plans (Free, Pro, Business and Premium) that bundle the CDN, AWS WAF, DDoS protection, Route 53 DNS, the TLS certificate and edge compute into a monthly fee with no overage charges. For awssinmapa.com the Free plan (0 USD per month) was chosen: if a video goes viral, the distribution doesn’t generate extra charges. That doesn’t make the whole website free. The plan covers what it includes; the domain, which is paid at GoDaddy, and any charge outside the plan are billed separately. The coverage and limits of each plan are on the official pricing page, and the real cost of the website will be clear once the bill is reviewed.
Configuring the distribution
- Domain:
awssinmapa.com, which the console detects as managed by Route 53. In “Add subdomain” you type onlywww. If you type the full name, the console concatenates it and generateswww.awssinmapa.com.awssinmapa.com, which no certificate covers. - Origin: Amazon S3, the
awssinmapa-webbucket, with the “Allow private S3 bucket access to CloudFront” option checked. This creates an Origin Access Control (OAC) and writes the bucket policy. - Security: AWS WAF comes included in the plan. Monitor mode is left unchecked: with it on, the rules only count requests and don’t block any.
- Certificate: the one already issued in
us-east-1. - Default root object:
index.html. It was empty; without it, the site root doesn’t know which file to return.
This is an example equivalent to the policy CloudFront wrote on the bucket, with the IDs replaced by placeholders:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::awssinmapa-web/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::<ACCOUNT>:distribution/<DISTRIBUTION>"
}
}
}
]
}
It allows a single action, s3:GetObject, to the CloudFront service, and only when the request comes from this distribution. Another distribution, even in the same account, can’t read the bucket.
Connecting the domain
With the distribution deployed, the “Route domains to CloudFront” → “Set up routing automatically” option creates four alias records in the zone: A and AAAA (IPv4 and IPv6) for awssinmapa.com and for www.awssinmapa.com. The first time they weren’t created and the zone still had three records instead of seven; you have to wait for the confirmation message and check the zone.
Diagnosis: why S3 returns 403 when the file doesn’t exist
With everything configured,
https://awssinmapa.comresponded with an S3 XML:AccessDenied. So did/img/logo.webp. The bucket policy was fine, the OAC was associated with the origin and the cache had been invalidated. The cause had nothing to do with permissions: when uploading the files, the whole folder had been uploaded, and everything lived inawssinmapa-web/index.htmlinstead of at the root.The misleading part is the code. When someone requests an object that doesn’t exist, S3 returns 404 only if that someone has
s3:ListBucket. If they don’t, it returns 403, because saying “doesn’t exist” would already reveal what’s in the bucket. CloudFront only hass3:GetObject, so every missing file arrives asAccessDenied. Before reviewing policies, check the object’s exact path.The same behavior explains the custom error page. A custom error response was created in the distribution that takes the 403, not the 404, and returns
/404.htmlwith a 404 code and a 10-second TTL. That way the visitor sees a “not found” page with the correct code. The flip side: a 403 that really was about permissions would also show that page, so when debugging it’s worth testing the file’s exact path.
Every time the files change, CloudFront may keep delivering the previous copy until it expires. An invalidation of /* asks it to forget what it stored and fetch fresh files from the origin.
Publishing with a git push: GitHub Actions and OIDC
Uploading files by hand and then invalidating the cache works for one page, but it becomes slow and error-prone as soon as the site grows. It had already happened twice: files in the wrong folder and an old page served from the cache. The solution was to move the site to a private GitHub repository, build it with Astro (a static site generator where articles are written in Markdown) and let GitHub Actions publish every change.
The “Publicar web” (Publish website) workflow runs on every push to the main branch:
- It installs dependencies with
npm ciand builds the site withnpm run build, which leaves the result indist/. - It gets temporary AWS credentials by assuming an IAM role with OIDC.
- It syncs
dist/with the bucket usingaws s3 sync dist s3://awssinmapa-web --delete. - It creates an invalidation of
/*on the distribution.
With --delete, sync removes from the destination any files that aren’t in dist/, the folder generated by the build. On the first run it deleted a video that had been uploaded by hand; thanks to versioning it remained recoverable as a previous version.
Why OIDC and not access keys
The old way to connect GitHub to AWS was to create an IAM user and store its access key as a repository secret. That key never expires and, if it leaks, it works from anywhere. With OpenID Connect (OIDC), GitHub presents AWS with a signed token that says which repository and which branch are running the workflow, and AWS Security Token Service (AWS STS) gives it credentials that last minutes. No long-lived AWS key is stored in GitHub: what travels is a signed token and temporary credentials.
The IAM setup has three parts:
- Identity provider
token.actions.githubusercontent.comwith audiencests.amazonaws.com. There is one per account: this one already existed for another project and was reused. - Role
github-actions-awssinmapa-web, created with the web identity wizard (organization, repository and branch). Its trust policy decides who can assume it. - Inline policy
publicar-web, with only what the workflow needs. This is the policy we created, with the account ID and the distribution ID hidden:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListarBucket",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::awssinmapa-web"
},
{
"Sid": "SubirYBorrarArchivos",
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::awssinmapa-web/*"
},
{
"Sid": "InvalidarCache",
"Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::<ACCOUNT>:distribution/<DISTRIBUTION>"
}
]
}
Look at the resources: s3:ListBucket is granted on the bucket (without /*) because it’s a bucket action, and the other two on the objects. The workflow needs to list so sync knows what changed and what to delete. (The Sid values are in Spanish: list bucket, upload and delete files, invalidate cache.) The role ARN, the bucket name and the distribution ID go in as repository variables (AWS_ROLE_ARN, S3_BUCKET, CLOUDFRONT_DISTRIBUTION_ID), not as secrets: they aren’t credentials.
Diagnosis: the
subthe console doesn’t know aboutThe first run with the role failed with
Not authorized to perform sts:AssumeRoleWithWebIdentity. The trust policy generated by the console expected thissub:
repo:OshinVillegas/awssinmapa-web:ref:refs/heads/mainTo see what GitHub was actually sending, a diagnostic step was added to the workflow that, only when authentication fails, prints four claims from the token (
sub,aud,repositoryandref), never the full token. Thesubcame in a different format:
repo:OshinVillegas@<OWNER_ID>/awssinmapa-web@<REPO_ID>:ref:refs/heads/mainGitHub changed the default
subformat: for repositories created after July 15, 2026, it includes the numeric owner ID and repository ID after each name. The reason is security. Names can be reused: if you delete a repository and someone else creates one with the same name, with the old format their workflow could assume your role. IDs are never reassigned.The fix was to put that exact
subin the trust policy, withStringEquals. The full policy is right below this box.The lesson goes beyond this case: when an identity federation fails, print the claims that actually arrive before touching the policy. Print only the ones you need, and never the full token.
This is how the role’s trust policy ended up, with the account and IDs hidden. It has two conditions: the audience (aud) and the subject (sub).
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<ACCOUNT>:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:OshinVillegas@<OWNER_ID>/awssinmapa-web@<REPO_ID>:ref:refs/heads/main"
}
}
}
]
}
Folder URLs and www with a CloudFront Function
Astro generates each page as a folder with its own index.html: the “What is AWS?” article lives in blog/que-es-aws/index.html. The visitor, however, requests /blog/que-es-aws/. The default root object doesn’t help: CloudFront only applies it at the distribution root, not in subfolders. With nothing else, that URL ends up in the S3 403.
The solution is a CloudFront Function: lightweight JavaScript code that runs at the network edge before or after CloudFront processes the request. The index-html-carpetas function (runtime cloudfront-js-2.0) does two things:
- If the requested path ends in
/, it appendsindex.htmlbefore looking up the file. The visitor still sees/blog/que-es-aws/in the address bar. - If the request arrives at
www.awssinmapa.com, it responds with a 301 redirect tohttps://awssinmapa.com, keeping the path and parameters. That way the site has a single canonical address, something search engines appreciate too.
The function is associated with the distribution’s default behavior (Default (*)), and its code lives in the repository at infra/cloudfront-index.js, alongside the rest of the site.
Diagnosis: viewer request and viewer response are not interchangeable
After associating the function, the whole website stopped working, logo included, with a 503:
The CloudFront function returned an invalid value: response.statusCode is missing. The function was associated with the wrong event.A CloudFront Function hooks into one of two moments. On viewer request it runs when the visitor’s request arrives, before looking in the cache or the origin: it’s the place to rewrite the path or redirect, and the function returns the modified request or a response of its own. On viewer response it runs when CloudFront is about to return the response, and what the function returns has to be a response, with its
statusCode. A function written to rewrite requests, placed on viewer response, returns an object withoutstatusCode, and CloudFront answers 503 to everything.The fix was to move the association to viewer request in Behaviors → Default → Function associations. Since the function affects every path, the error isn’t partial: if the whole website goes down right after associating a function, check the event type first.
The two tweaks that finish the technical part
Security headers. CloudFront can add HTTP headers to every response through a response headers policy. AWS offers managed policies, and SecurityHeadersPolicy was assigned to the default behavior. That policy adds, among others, HSTS (the browser remembers to always use HTTPS), X-Content-Type-Options: nosniff, X-Frame-Options (prevents another site from embedding yours in a frame) and Referrer-Policy. For a static site it’s a security improvement without writing any code.
Lifecycle rule. With versioning on and a publish on every push, the bucket piles up previous versions of every file. The borrar-versiones-viejas (delete old versions) rule keeps them in check:
- it deletes noncurrent versions after 30 days;
- it cleans up delete markers that no longer protect any version;
- it removes incomplete multipart uploads after 7 days.
Current versions, that is, the website people see, are left untouched. The result is a one-month window to recover a file deleted by mistake, like the video taken by the first --delete, without paying for indefinite storage of history nobody will use.
The errors, in a table
If you got here looking for an error message, this is the short version:
| Symptom | Cause | Fix |
|---|---|---|
AccessDenied in S3 XML, even for images |
The files were inside a folder, not at the bucket root; S3 returns 403 for a missing object if the requester can’t list | Upload the files to the root, delete the folder and invalidate /* |
The certificate doesn’t cover www.awssinmapa.com.awssinmapa.com |
The full name was typed in “Add subdomain” | Type only www |
DNS_PROBE_FINISHED_NXDOMAIN |
The alias records were missing, or the computer cached the “doesn’t exist” answer | Confirm the A and AAAA records in the zone; test from another network or clear the local DNS cache |
Not authorized to perform sts:AssumeRoleWithWebIdentity |
The trust policy used the old sub format, without IDs |
Print the token claims and copy the exact sub with StringEquals |
503: response.statusCode is missing across the whole site |
The CloudFront Function was on viewer response | Associate it on viewer request |
| A file uploaded by hand disappeared | aws s3 sync --delete makes the bucket match the build |
Recover the previous version; everything published goes through the repository |
What this architecture leaves behind
The result is a site with HTTPS, served from CloudFront’s global network on the Free plan, with no overage charges on the distribution; a bucket with no public access, which visitors reach through CloudFront with OAC; and a publishing process that doesn’t store long-lived AWS keys in GitHub. Each piece has a single responsibility: Route 53 answers where the site is, S3 stores the files, ACM proves identity, CloudFront controls the entrance and GitHub Actions publishes.
The errors leave three ideas that are useful beyond this project. An S3 403 isn’t always a permissions problem: first confirm the object exists where you think it does. When an identity federation fails, look at the real claims before touching the policy. And in CloudFront, the event you associate a function with matters as much as its code.
The natural next step is to review the real bill to find out how much all this costs. To filter it by project, the Proyecto tag has to be activated for cost allocation, which is still pending confirmation.
References
- Amazon CloudFront: flat-rate pricing plans
- Amazon CloudFront: pricing
- Amazon CloudFront: restricting access to an Amazon S3 origin (OAC)
- Amazon CloudFront: SSL/TLS certificate requirements
- Amazon CloudFront: default root object
- AWS Blog: directory indexes with CloudFront Functions
- AWS re:Post: why S3 returns 403 instead of 404
- GitHub Changelog: immutable subject claims for GitHub Actions OIDC tokens
- GitHub Docs: OpenID Connect reference
If this article helped you, share it with someone who is just getting started with the cloud. See you in the next AWS Unmapped article.
