Hospedando sites estáticos e entrega por CDN
Entregue um site estático diretamente de um bucket S3 e acelere a distribuição global usando uma CDN do CloudFront à frente dele.
Hospedando sites estáticos e entrega por CDN é uma aula grátis de AWS for Backend Developers (EC2, S3, RDS, Lambda) no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de AWS for Backend Developers (EC2, S3, RDS, Lambda), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de AWS for Backend Developers (EC2, S3, RDS, Lambda) inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
S3 as a Web Server
Beyond storing files, S3 can host a static website, HTML, CSS, JS, and images, with no servers to manage. It is cheap, scalable, and a perfect fit for single-page apps and documentation sites.
Enabling Static Hosting
You enable the static website hosting feature on the bucket and specify an index document (the home page) and an error document.
Index and Error Documents
The index document (often index.html) is served for the root and folder URLs. The error document handles 4xx responses, useful for SPA routing where you point errors back to index.html.
Uploading Your Site
Sync your build output into the bucket. The AWS CLI sync command uploads only changed files.
aws s3 sync ./dist s3://my-site-bucket --deleteContent Types Matter
S3 serves files with the Content-Type stored as metadata. If a CSS file is served as plain text, browsers ignore it. The CLI usually infers types, but verify for unusual extensions.
The Website Endpoint
Static hosting exposes a regional website endpoint URL. It is HTTP only and not ideal for production, which is exactly why we add a CDN next.
http://my-site-bucket.s3-website-us-east-1.amazonaws.comIntroducing CloudFront
CloudFront is AWS's content delivery network. It caches your site at edge locations worldwide, so users get fast responses from a nearby server and your bucket sees less load.
Origins and Distributions
A CloudFront distribution points at an origin (your S3 bucket). CloudFront fetches from the origin on a cache miss and serves the cached copy on subsequent requests.
HTTPS and Custom Domains
CloudFront gives you free HTTPS via AWS Certificate Manager and lets you attach a custom domain like www.example.com, things the raw S3 endpoint cannot do.
Locking Down the Bucket
For security, keep the bucket private and let only CloudFront read it using an Origin Access Control (OAC). Visitors reach content through the CDN, never the bucket directly.
Cache Invalidation
CloudFront caches aggressively. After deploying new content, invalidate the cache so users get the latest version instead of a stale copy.
aws cloudfront create-invalidation \
--distribution-id E123ABC \
--paths "/*"Quick Check
Test your static hosting knowledge.
Recap: Global Static Sites
You can now ship a static site on AWS:
- Enable S3 static website hosting with index/error documents.
aws s3 syncdeploys your build.- CloudFront adds edge caching, HTTPS, and custom domains.
- Use OAC to keep the bucket private and invalidate the cache on deploy.
Perguntas Frequentes
A aula “Hospedando sites estáticos e entrega por CDN” é grátis?
Sim — o texto completo de “Hospedando sites estáticos e entrega por CDN” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de AWS for Backend Developers (EC2, S3, RDS, Lambda), atualize para CoddyKit PRO. O curso de AWS for Backend Developers (EC2, S3, RDS, Lambda) inclui 4 aulas no total.
O que vou aprender em “Hospedando sites estáticos e entrega por CDN”?
Entregue um site estático diretamente de um bucket S3 e acelere a distribuição global usando uma CDN do CloudFront à frente dele. Você pratica AWS for Backend Developers (EC2, S3, RDS, Lambda) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Nenhuma experiência prévia é necessária. AWS for Backend Developers (EC2, S3, RDS, Lambda) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Hospedando sites estáticos e entrega por CDN”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Sim. Cada aula de AWS for Backend Developers (EC2, S3, RDS, Lambda) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Buckets e objetos do S3 explicados
- Versionamento e políticas de ciclo de vida do S3
- Protegendo o acesso aos dados do S3
- Hospedando sites estáticos e entrega por CDN