Configuration Files
4 files
Production-ready configuration files with detailed comments and best practices. Each file works together as a complete deployment solution.
Astro configuration for static site generation
javascript
import { defineConfig } from 'astro/config';
// https://astro.build/config
export default defineConfig({
output: 'static',
build: {
inlineStylesheets: 'auto',
},
// Optional: Add site URL for sitemap generation
site: 'https://d1234567890.cloudfront.net',
// Optional: Add base path if deploying to subdirectory
// base: '/my-app',
}); Pro Tips
- β‘ output: "static" generates pure HTML/CSS/JS
- π― inlineStylesheets: "auto" optimizes CSS delivery
- πΊοΈ site: URL enables sitemap generation
- π‘ Astro is perfect for content-heavy sites
- π¦ Zero JavaScript by default (opt-in hydration)
- π Fastest static site generator (benchmarks)
AWS infrastructure for Astro static site
terraform
# Terraform for Astro on AWS S3 + CloudFront
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = var.aws_region
}
variable "aws_region" {
default = "us-east-1"
}
variable "app_name" {
default = "my-astro-site"
}
# S3 Bucket
resource "aws_s3_bucket" "website" {
bucket = "${var.app_name}-website"
}
resource "aws_s3_bucket_website_configuration" "website" {
bucket = aws_s3_bucket.website.id
index_document {
suffix = "index.html"
}
error_document {
key = "404.html"
}
}
resource "aws_s3_bucket_public_access_block" "website" {
bucket = aws_s3_bucket.website.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_policy" "website" {
bucket = aws_s3_bucket.website.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "PublicReadGetObject"
Effect = "Allow"
Principal = "*"
Action = "s3:GetObject"
Resource = "${aws_s3_bucket.website.arn}/*"
}
]
})
depends_on = [aws_s3_bucket_public_access_block.website]
}
# CloudFront Distribution
resource "aws_cloudfront_distribution" "website" {
enabled = true
is_ipv6_enabled = true
default_root_object = "index.html"
price_class = "PriceClass_100"
origin {
domain_name = aws_s3_bucket.website.bucket_regional_domain_name
origin_id = "S3-${var.app_name}"
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
target_origin_id = "S3-${var.app_name}"
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
compress = true
}
custom_error_response {
error_code = 404
response_code = 404
response_page_path = "/404.html"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
}
# Outputs
output "s3_bucket_name" {
value = aws_s3_bucket.website.id
}
output "cloudfront_distribution_id" {
value = aws_cloudfront_distribution.website.id
}
output "website_url" {
value = "https://${aws_cloudfront_distribution.website.domain_name}"
} Pro Tips
- π° Costs ~$0.50-3/month for typical blog/docs site
- π CloudFront: 450+ edge locations worldwide
- β‘ 99% cache hit rate = minimal S3 costs
- π HTTPS included with CloudFront certificate
- π‘ Add custom domain with Route 53 + ACM
- π S3: $0.023/GB storage, CloudFront: $0.085/GB transfer
- π― Perfect for blogs, documentation, marketing sites
- β οΈ Run "terraform destroy" when done testing
Astro project dependencies and scripts
json
{
"name": "my-astro-site",
"type": "module",
"version": "0.0.1",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro",
"deploy": "npm run build && aws s3 sync dist/ s3://my-astro-site-website --delete"
},
"dependencies": {
"astro": "^4.0.0"
},
"devDependencies": {
"@astrojs/check": "^0.3.0",
"typescript": "^5.3.0"
}
} Pro Tips
- β‘ "astro check" validates TypeScript before build
- π "deploy" script for manual deployments
- π‘ Astro 4.0+ includes View Transitions API
- π¦ Minimal dependencies = fast installs
- π― Update S3 bucket name in deploy script
- π§ Use GitHub Actions for automated deployments
Environment variables for AWS deployment
bash
# AWS Configuration AWS_REGION=us-east-1 S3_BUCKET=my-astro-site-website CLOUDFRONT_DISTRIBUTION_ID=E1234567890ABC # Public variables (available in Astro) PUBLIC_API_URL=https://api.example.com PUBLIC_SITE_URL=https://d1234567890.cloudfront.net PUBLIC_GA_ID=G-XXXXXXXXXX
Pro Tips
- π PUBLIC_ prefix makes variables available in Astro
- β οΈ All PUBLIC_ variables are exposed in client bundle
- π‘ Access with import.meta.env.PUBLIC_API_URL
- π« Never commit .env to git (add to .gitignore)
- π Copy to .env for local development
- π― GitHub Actions uses repository secrets