This project demonstrates how to use Pulumi to provision and manage AWS infrastructure for hosting a static website. It creates an S3 bucket for content storage and a CloudFront distribution to serve that content with low latency globally.
- S3 Bucket: Securely stores static website files
- CloudFront Distribution: Serves content with low latency from edge locations worldwide
- Origin Access Identity: Ensures S3 content is only accessible through CloudFront
- Synced Folder Component: Automatically syncs local files to S3 during deployment
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ │ │ │ │ │
│ Users │────▶│ CloudFront │────▶│ S3 Bucket │
│ │ │ Distribution │ │ │
└───────────────┘ └───────────────┘ └───────────────┘
│ ▲
│ │
▼ │
┌───────────────┐ ┌───────────────┐
│ Origin │ │ Bucket │
│ Access │────▶│ Policy │
│ Identity │ │ │
└───────────────┘ └───────────────┘
- Users request content from the CloudFront URL
- CloudFront Distribution serves cached content or forwards requests to the origin
- Origin Access Identity provides secure access to the S3 bucket
- Bucket Policy ensures only CloudFront can access the S3 bucket content
- S3 Bucket stores the static website files
aws.s3.BucketV2
: The S3 bucket that stores the website contentaws.cloudfront.OriginAccessIdentity
: Secures access to the S3 bucketaws.s3.BucketPolicy
: Configures permissions for CloudFront accessaws.cloudfront.Distribution
: Distributes content globally with low latencysynced.S3BucketFolder
: Syncs local files to the S3 bucket during deployment
- Node.js (v14 or later)
- Pulumi CLI
- AWS CLI configured with appropriate credentials
- Pulumi ESC (optional, for credential management)
-
Clone this repository:
git clone https://github.com/cnunciato/hello-pulumi.git cd hello-pulumi
-
Install dependencies:
npm install
-
Configure AWS region:
pulumi config set aws:region us-west-2
-
Deploy the infrastructure:
pulumi up
-
After deployment, the CloudFront URL will be displayed in the outputs.
index.ts
: The main Pulumi program that defines the infrastructurewebsite/
: Directory containing website files that are synced to S3Pulumi.yaml
andPulumi.dev.yaml
: Pulumi project and stack configuration files
To update the website content:
- Modify files in the
website/
directory - Run
pulumi up
to deploy the changes - The Synced Folder component will automatically update the S3 bucket with your changes
To remove all resources created by this project:
pulumi destroy
MIT
This project was inspired by Pulumi's examples and documentation on deploying static websites to AWS.