🛠️ Step 1: Create the Source S3 Bucket
✅ Enable Versioning
CodePipeline uses version IDs to identify changes, so versioning must be enabled:
Go to S3 Console > Create a bucket (e.g., my-source-bucket)
Enable Versioning under Bucket Versioning section
🗃️ Step 2: Create the Production S3 Bucket
✅ Enable Public Access
This is required to serve content over the internet via S3 website hosting.
Create a new bucket (e.g., my-production-bucket)
Disable Block all public access
Save changes
🌐 Enable Static Website Hosting
Go to Bucket > Properties
Scroll to Static website hosting
Choose Enable
Select Host a static website
Set:
Index document: index.html
Error document: error.html
🛡️ Add Bucket Policy
To allow public access to the website content:
Go to Bucket > Permissions > Bucket policy
Paste the policy from bucket-policy.json
📦 Step 3: Upload Website Files
Download the sample static site ZIP:
Upload it to the source S3 bucket (e.g., my-source-bucket)
🔄 Step 4: Create the CodePipeline
Go to AWS CodePipeline > Create pipeline
Name your pipeline (e.g., S3-StaticWebsite-Pipeline)
Allow AWS to create a new service role
🔹 Add Source Stage
Provider: Amazon S3
Bucket: my-source-bucket
Object Key: my-website.zip
🚫 Skip Build & Test Stage
We're not using a build or test stage in this simple use case.
🔸 Add Deploy Stage
Provider: Amazon S3
Bucket: my-production-bucket
Enable Extract file before deploy
✅ Final Step: Review & Create Pipeline
Once the pipeline is created, it should trigger automatically and deploy the contents of my-website.zip into the production bucket.
❓ Why is the S3 Website Not Accessible?
Make sure:
- Static website hosting is enabled
- Public access is not blocked
- Bucket policy allows public read access
- Files are deployed correctly (check for index.html)
Access it via the S3 website endpoint found under Bucket > Properties > Static Website Hosting.
🌍 Deploy to Multiple S3 Buckets
To support multiple environments (e.g., prod, stage, dev):
- Create additional public S3 buckets with static website hosting
- Add the same bucket policy to each
- Update the CodePipeline IAM role to include permissions for new buckets
🧩 Add Extra Deploy Actions in CodePipeline
Go to your pipeline > Edit
Edit the Deploy stage
Click Add action
Set:
Action name (e.g., DeployToStage)
Provider: Amazon S3
Target bucket: my-stage-bucket
Extract before deploy: ✅
🔁 Manually Trigger the Pipeline
To redeploy:
Open the pipeline
Click Release change
📌 Wrap-up
This guide walks you through a full S3 to S3 static site deployment pipeline using AWS CodePipeline. You can extend this setup to deploy the same artifacts to multiple environments easily.
Top comments (0)