Skip to content

Instantly share code, notes, and snippets.

@whoeverest
Last active February 16, 2025 10:53
Show Gist options
  • Save whoeverest/744a94078fd6eed84ac8e26e8879bbae to your computer and use it in GitHub Desktop.
Save whoeverest/744a94078fd6eed84ac8e26e8879bbae to your computer and use it in GitHub Desktop.
How to deploy an Astro (i.e static) website to S3/CloudFront using Github Actons
name: Deploy to S3
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Install dependencies
run: npm ci
- name: Build website
run: npm run build
- name: Deploy to S3 and invalidate CloudFront cache
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
run: |
aws s3 sync dist/ s3://example-bucket --delete
aws cloudfront create-invalidation --distribution-id EXAMPLE123 --paths "/*"
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowS3BucketManipulation",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::example-bucket/*"
},
{
"Sid": "AllowS3BucketListing",
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": "arn:aws:s3:::example-bucket"
},
{
"Sid": "CFInvalidation",
"Effect": "Allow",
"Action": "cloudfront:CreateInvalidation",
"Resource": "arn:aws:cloudfront::1234567890:distribution/EXAMPLE123"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment