AWS Builder Center
Automating AWS Deployments with GitHub Actions, Amazon S3, and CloudFront: A Practical CI/CD Guide

Automating AWS Deployments with GitHub Actions, Amazon S3, and CloudFront: A Practical CI/CD Guide

Deploying a website manually may seem straightforward at first. However, as applications evolve and development teams grow, manual deployments introduce operational challenges, including inconsistent releases, configuration errors, and unnecessary repetitive work.

The future will be Cloud ☁️
Continuous Integration and Continuous Deployment (CI/CD) help address these challenges by automating software validation and delivery.
In this hands-on tutorial, we will explore how to build a CI/CD pipeline using GitHub Actions, Amazon Simple Storage Service (Amazon S3), Amazon CloudFront, and AWS Identity and Access Management (IAM).
Our objective is to create an automated deployment process that publishes a static website to AWS whenever changes are pushed to the main branch of a GitHub repository.
We will also implement OpenID Connect (OIDC) authentication to avoid storing long-lived AWS credentials in GitHub.
By the end of this tutorial, you will understand how these services work together to create a secure, repeatable, and maintainable deployment workflow.
---
1. Understanding the Architecture
Before implementing the solution, let's understand the role of each service.
Service| Responsibility GitHub| Stores and manages the application's source code GitHub Actions| Automates validation and deployment AWS IAM| Controls access to AWS resources OpenID Connect (OIDC)| Enables authentication using temporary AWS credentials Amazon S3| Stores the static website files Amazon CloudFront| Delivers website content through a global content delivery network AWS CLI| Executes deployment commands from the pipeline
How the Deployment Works
The deployment process follows this sequence:
1. A developer modifies the website source code. 2. The changes are committed and pushed to GitHub. 3. GitHub Actions automatically starts the CI/CD workflow. 4. The workflow validates the required application files. 5. GitHub Actions requests an OIDC token and assumes an authorized AWS IAM role. 6. The workflow synchronizes the website files with Amazon S3. 7. A CloudFront cache invalidation is requested. 8. Visitors can access the updated website through the CloudFront HTTPS endpoint after the deployment and cache update complete.
The architecture separates source control, deployment automation, storage, and content delivery.
Importantly, the S3 bucket remains private. CloudFront accesses its contents through Origin Access Control (OAC), rather than exposing the bucket directly to the internet.
---
2. Prerequisites
Before starting, make sure you have the following:
Requirement| Purpose AWS account| Access to AWS services GitHub account| Source code repository and automation Git| Version control AWS CLI v2| AWS configuration and deployment commands Code editor| Editing website and workflow files Appropriate AWS permissions| Creating S3, CloudFront, and IAM resources
Basic familiarity with Git, HTML, and AWS is helpful but not mandatory.
Cost consideration: Amazon S3, CloudFront, and related services may generate charges depending on storage, requests, data transfer, and usage. Review AWS pricing and configure billing alerts before starting the laboratory.
---
3. Creating the Static Website
We will begin by creating a simple static website.
Create a directory named:
"aws-github-actions-cicd"
Inside this directory, create the following structure:
aws-github-actions-cicd/ ├── site/ │ ├── index.html │ └── style.css └── .github/ └── workflows/ └── deploy.yml
The "site" directory contains the application files that will be published to Amazon S3.
Creating index.html
Create the file "site/index.html":
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>AWS CI/CD Demo</title> <link rel="stylesheet" href="style.css"> </head> <body> <main class="container"> <h1>Deployment Successful!</h1> <p> This website is deployed automatically using GitHub Actions, Amazon S3, and Amazon CloudFront. </p> <p>Version: 1.0</p> </main> </body> </html>
Creating style.css
Create the file "site/style.css":
body { margin: 0; font-family: Arial, sans-serif; background: #0f172a; color: #ffffff; min-height: 100vh; display: flex; justify-content: center; align-items: center; }
.container { text-align: center; padding: 40px; max-width: 700px; }
h1 { color: #38bdf8; font-size: 2.5rem; }
p { font-size: 1.1rem; line-height: 1.6; }
This lightweight application allows us to focus on deployment automation without introducing additional frameworks or build dependencies.
---
4. Creating an Amazon S3 Bucket
Amazon S3 will store the static files used by our website.
Open the AWS Management Console and navigate to Amazon S3.
Select Create bucket.
Configure the following settings:
Setting| Recommended Value Bucket name| A globally unique name, such as "my-cicd-demo-123456789012" AWS Region| "us-east-1" for this example Object Ownership| Bucket owner enforced Block Public Access| Keep all options enabled Versioning| Optional, recommended for recovery Default encryption| SSE-S3
The bucket name must be globally unique within the relevant Amazon S3 namespace.
For this tutorial, we will use the placeholder:
"YOUR_BUCKET_NAME"
Replace it with your actual bucket name whenever it appears.
Why Keep the Bucket Private?
Although Amazon S3 supports static website hosting, we will not enable its public website endpoint.
Instead, CloudFront will access the private bucket using OAC.
This architecture offers several advantages:
- Prevents direct anonymous access to the S3 objects. - Centralizes public content delivery through CloudFront. - Supports HTTPS for visitors. - Allows CloudFront caching and content delivery optimization. - Provides a clearer separation between storage and public access.
After creating the bucket, record its name and AWS Region.
---
5. Configuring Amazon CloudFront
Amazon CloudFront is AWS's content delivery network (CDN).
It delivers content through geographically distributed edge locations, helping reduce latency for users in different regions.
Creating the Distribution
Navigate to the Amazon CloudFront console and create a distribution.
Use the following configuration:
Setting| Configuration Origin| The Amazon S3 bucket created earlier Origin type| Regular S3 bucket origin Origin access| Origin Access Control (OAC) OAC signing behavior| Sign requests Viewer protocol policy| Redirect HTTP to HTTPS Allowed HTTP methods| GET, HEAD Default root object| "index.html"
When configuring OAC, select the recommended request-signing option.
Do not use the S3 static website endpoint as the origin, because OAC is designed to work with regular S3 bucket origins.
Configuring the S3 Bucket Policy
CloudFront requires permission to read objects from the private bucket.
In the S3 bucket permissions, add a policy similar to the following:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowCloudFrontReadAccess", "Effect": "Allow", "Principal": { "Service": "cloudfront.amazonaws.com" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*", "Condition": { "StringEquals": { "AWS:SourceArn": "arn:aws:cloudfront::AWS_ACCOUNT_ID:distribution/DISTRIBUTION_ID" } } } ] }
Replace:
- "YOUR_BUCKET_NAME" with your S3 bucket name. - "AWS_ACCOUNT_ID" with your 12-digit AWS account ID. - "DISTRIBUTION_ID" with your CloudFront distribution ID.
Some CloudFront console workflows can generate or help update the required bucket policy automatically.
The "AWS:SourceArn" condition restricts the permission to requests associated with the specified CloudFront distribution.
Once the distribution is deployed, AWS provides a domain similar to:
This will be the public endpoint for our website.
The site will become accessible after its files are uploaded to S3 and the distribution is correctly configured.
---
6. Configuring GitHub Authentication with AWS OIDC
One of the most important aspects of a CI/CD pipeline is credential management.
A traditional approach involves creating an IAM user, generating an access key, and storing that key as a GitHub secret.
However, long-lived credentials introduce unnecessary security risks.
For this project, we will use OpenID Connect (OIDC).
OIDC enables GitHub Actions to request temporary AWS credentials by assuming an IAM role.
Step 1: Create an OIDC Identity Provider
Open the AWS IAM console.
Navigate to:
IAM → Identity providers → Add provider
Select OpenID Connect and configure:
Field| Value Provider type| OpenID Connect Provider URL| " https://token.actions.githubusercontent.com " Audience| "sts.amazonaws.com"
Create the provider.
If the provider already exists in your AWS account, you can reuse it.
Step 2: Create an IAM Role
Create an IAM role named:
"GitHubActionsS3DeployRole"
Configure its trust relationship to allow the GitHub OIDC identity provider to assume the role.
The trust policy must restrict access to the intended GitHub repository and deployment branch.
For repositories using the standard branch-based OIDC subject format, an example trust policy is:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::AWS_ACCOUNT_ID:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com", "token.actions.githubusercontent.com:sub": "repo:GITHUB_OWNER/REPOSITORY_NAME:ref:refs/heads/main" } } } ] }
Replace the placeholders with your account and repository information.
Important: GitHub OIDC subject formats can vary according to repository configuration, repository creation date, customized claims, and GitHub environments. Verify the actual subject format for your repository before applying this policy. Newer repository configurations may include repository and organization identifiers in the subject.
The purpose of the trust policy is to ensure that only the explicitly authorized GitHub workflow context can obtain deployment credentials.
Step 3: Create a Least-Privilege IAM Policy
The deployment workflow needs permission to synchronize website files with S3 and invalidate the CloudFront cache.
Create an IAM policy with the following permissions:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListDeploymentBucket", "Effect": "Allow", "Action": [ "s3:ListBucket" ], "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME" }, { "Sid": "ManageWebsiteObjects", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:DeleteObject" ], "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*" }, { "Sid": "InvalidateCloudFrontCache", "Effect": "Allow", "Action": [ "cloudfront:CreateInvalidation" ], "Resource": "arn:aws:cloudfront::AWS_ACCOUNT_ID:distribution/DISTRIBUTION_ID" } ] }
Attach this policy to "GitHubActionsS3DeployRole".
This policy is designed for a basic deployment to an S3 bucket using SSE-S3 encryption. Additional permissions may be required if your architecture uses AWS KMS, additional resources, or more advanced deployment operations.
Notice that the policy does not grant broad administrative permissions.
This follows the principle of least privilege: the pipeline should receive only the permissions required to perform its intended operations.
---
7. Creating the GitHub Repository
Create a new GitHub repository named:
"aws-github-actions-cicd"
From your local project directory, initialize Git and connect it to the remote repository.
git init git add . git commit -m "Initial static website" git branch -M main git remote add origin  https://github.com/YOUR\_USERNAME/aws-github-actions-cicd.git  git push -u origin main
Replace "YOUR_USERNAME" with your GitHub username.
If the remote repository was initialized with a README or other files, reconcile the existing history before pushing.
At this stage, the repository should contain the website files.
Next, we will configure the deployment workflow.
---
8. Configuring GitHub Actions
GitHub Actions uses YAML workflow files stored in:
".github/workflows/"
Create the file:
".github/workflows/deploy.yml"
Before writing the workflow, configure the required repository variables.
Navigate to:
GitHub Repository → Settings → Secrets and variables → Actions → Variables
Create the following repository variables:
Variable| Example "AWS_REGION"| "us-east-1" "S3_BUCKET"| Your S3 bucket name "CLOUDFRONT_DISTRIBUTION_ID"| Your CloudFront distribution ID "AWS_ROLE_ARN"| ARN of the deployment IAM role
These values identify deployment resources and do not contain permanent AWS access keys.
The Complete GitHub Actions Workflow
name: Deploy Static Website to AWS
on: push: branches: - main
workflow_dispatch:
permissions: id-token: write contents: read
concurrency: group: production-deployment cancel-in-progress: false
jobs: deploy: name: Deploy to S3 and CloudFront runs-on: ubuntu-latest
steps:
\- name: Checkout repository
uses: actions/checkout\@v4

\- name: Validate website files
run: |
test -f site/index.html
test -f site/style.css
echo "Required website files found."

\- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials\@v4
with:
role-to-assume: $\{\{ vars.AWS\_ROLE\_ARN }}
aws-region: $\{\{ vars.AWS\_REGION }}

\- name: Verify AWS identity
run: aws sts get-caller-identity

\- name: Deploy website to S3
run: |
aws s3 sync ./site/ \\
s3://$\{\{ vars.S3\_BUCKET }}/ \\
\--delete

\- name: Invalidate CloudFront cache
run: |
aws cloudfront create-invalidation \\
\--distribution-id $\{\{ vars.CLOUDFRONT\_DISTRIBUTION\_ID }} \\
\--paths "/\*"

\- name: Deployment summary
run: |
echo "Deployment commands completed."
echo "S3 synchronization succeeded."
echo "CloudFront invalidation requested."
This workflow is designed to run when changes are pushed to the "main" branch. It can also be started manually through GitHub's workflow interface.
The example uses major-version action tags for readability. For production systems, pin third-party actions to reviewed commit SHAs and use approved action versions.
Understanding the Workflow
Component| Function "on: push"| Triggers deployment after a push to "main" "workflow_dispatch"| Allows manual execution "id-token: write"| Allows the workflow to request an OIDC token "contents: read"| Allows the workflow to read repository contents "concurrency"| Prevents simultaneous executions in the same deployment group "actions/checkout"| Downloads repository content Validation step| Confirms required files exist "configure-aws-credentials"| Obtains temporary AWS credentials "aws s3 sync"| Synchronizes the website files "--delete"| Removes destination objects not present in the source directory "create-invalidation"| Requests CloudFront cache invalidation
Important Deployment Considerations
The "--delete" option is useful for keeping the destination synchronized with the repository. However, it can remove files that are not included in the source directory.
For this reason, use a dedicated deployment bucket or prefix, and avoid mixing application files with unrelated data.
The validation step in this example only verifies the presence of required files. A production pipeline should also include appropriate automated tests, linting, dependency checks, and security scanning.
The workflow requests a CloudFront invalidation but does not wait for the invalidation to complete.
Also, although the concurrency setting prevents overlapping deployment runs, production teams should consider deployment ordering, protected environments, and release approval mechanisms.
---
9. Executing the First Deployment
After creating the workflow, commit and push the changes:
git add . git commit -m "Add automated AWS deployment" git push origin main
Navigate to the GitHub repository and open the Actions tab.
Select the deployment workflow.
You should see the workflow progressing through the configured steps.
A successful execution should confirm that:
1. GitHub successfully checked out the repository. 2. The required website files were found. 3. The workflow obtained temporary AWS credentials. 4. The S3 synchronization completed. 5. CloudFront accepted the invalidation request.
If any step fails, inspect the logs associated with that step before proceeding.
Verifying the Deployment
Open the Amazon S3 console and inspect the destination bucket.
You should find:
index.html style.css
Next, open your CloudFront distribution domain in a browser.
For example:
If the deployment and distribution are correctly configured, the page should display:
Deployment Successful!
The website is now being delivered through Amazon CloudFront.
---
10. Testing Continuous Deployment
To verify that the pipeline responds to source code changes, modify the website.
Open "site/index.html" and change:
<p>Version: 1.0</p>
To:
<p>Version: 2.0 - Automated Deployment</p>
Save the file and execute:
git add . git commit -m "Update website to version 2.0" git push origin main
GitHub Actions should automatically start another workflow execution.
After the S3 synchronization and CloudFront invalidation complete, refresh the website.
The updated version should become visible.
This demonstrates the central benefit of continuous deployment: code changes can be delivered through an automated and repeatable process without manually uploading files through the AWS console.
---
11. Security Best Practices
Automation improves delivery efficiency, but security must remain a central part of the architecture.
The following practices are recommended:
Security Practice| Benefit OIDC authentication| Avoids long-lived AWS credentials in GitHub Least-privilege IAM policies| Limits the impact of compromised credentials Private S3 bucket| Prevents unintended public access to origin files CloudFront OAC| Restricts access to the S3 origin HTTPS enforcement| Protects data in transit between visitors and CloudFront Protected GitHub branches| Reduces the risk of unauthorized production changes Pinned GitHub Actions| Reduces exposure to unexpected third-party action changes AWS CloudTrail| Supports auditing of AWS API activity S3 versioning| Can help recover previous object versions
Additional Recommendations
For more advanced environments, consider separating development, staging, and production deployments.
Use GitHub environments with deployment protection rules, require pull request reviews, and restrict who can modify workflow files.
You should also monitor AWS usage, configure cost alerts, and review IAM policies periodically.
Security is not a single configuration step. It is an ongoing part of the software delivery lifecycle.
---
12. Troubleshooting Common Issues
During implementation, you may encounter authentication, permission, or content delivery errors.
The following table summarizes common issues.
Problem| Possible Cause| Suggested Solution "AccessDenied" during S3 deployment| Missing IAM permissions| Review the role policy and bucket restrictions "Not authorized to perform sts:AssumeRoleWithWebIdentity"| Incorrect OIDC trust policy| Verify provider, audience, subject, repository, and branch CloudFront returns HTTP 403| Incorrect OAC or bucket policy| Check the CloudFront distribution ARN and S3 permissions CloudFront returns HTTP 404| Requested object does not exist| Verify uploaded files and object paths Website displays an older version| Cached content| Check invalidation status and cache configuration GitHub workflow does not start| Incorrect trigger or workflow location| Verify the YAML file and branch configuration Deployment removes unexpected files| "aws s3 sync --delete"| Review the source directory and destination prefix
One important detail is that CloudFront's default root object configuration applies to requests for the distribution root.
It does not automatically implement single-page application routing for every nested path.
Applications using client-side routing may require additional CloudFront error-response or rewrite configuration.
---
13. Improving the Pipeline for Production
The implementation presented in this tutorial provides a foundation for deployment automation.
However, production environments often require additional capabilities.
Automated Testing
Add unit tests, integration tests, and static analysis before deploying the application.
A deployment should only proceed when the required quality checks pass.
Separate Environments
Use dedicated resources for development, staging, and production.
This reduces the risk of experimental changes affecting production users.
Deployment Approvals
Configure GitHub environments and branch protection policies to require approval before production releases.
Infrastructure as Code
Consider managing S3 buckets, CloudFront distributions, and IAM resources using AWS CloudFormation, AWS CDK, or Terraform.
Infrastructure as Code helps make infrastructure changes version-controlled, reviewable, and reproducible.
Smarter Cache Management
Invalidating all CloudFront objects with "/*" is simple for a laboratory, but it may not be the most efficient strategy for a large application.
A more advanced deployment can use versioned asset filenames, targeted invalidations, and appropriate "Cache-Control" headers.
For example, HTML documents can use shorter cache lifetimes while fingerprinted JavaScript and CSS assets can be cached for longer periods.
Rollback Strategy
Consider enabling S3 versioning and preserving previously validated build artifacts.
A production rollback should restore a known-good release and ensure CloudFront serves the restored content.
---
14. Expected Results and Key Learnings
By completing this laboratory, you should have an automated deployment architecture with the following capabilities:
Capability| Expected Outcome Source control| Website files managed through GitHub Deployment trigger| Automatic execution after a push to "main" Authentication| Temporary AWS credentials through OIDC File synchronization| Automated publication to Amazon S3 Content delivery| Website accessible through CloudFront Transport security| HTTPS access for visitors Cache management| Automatic CloudFront invalidation request Auditability| Deployment history visible in GitHub Actions
The laboratory illustrates how relatively simple AWS services can be combined to create a practical software delivery workflow.
It also highlights the importance of treating security, permissions, and operational reliability as part of deployment automation rather than as separate concerns.
---
15. Cleaning Up AWS Resources
After completing the laboratory, remove resources that are no longer required to avoid unnecessary charges.
Recommended cleanup steps:
1. Disable or remove the GitHub deployment workflow. 2. Empty the dedicated S3 bucket. 3. Disable and delete the CloudFront distribution. 4. Delete the S3 bucket. 5. Remove the dedicated IAM deployment role and its custom policy. 6. Remove the OIDC provider only if no other workloads depend on it. 7. Review AWS Billing and Cost Management for remaining usage.
Before deleting any resource, confirm that it is not shared with another application or environment.
---
Conclusion
Implementing CI/CD with GitHub Actions, Amazon S3, and Amazon CloudFront is a practical way to improve the reliability and consistency of static website deployments.
By combining source control, automated workflows, temporary AWS credentials, private object storage, and global content delivery, we can establish a deployment process that reduces manual intervention while supporting essential security practices.
One of the most valuable aspects of this architecture is the use of OpenID Connect.
Instead of storing permanent AWS access keys in GitHub, the workflow obtains temporary credentials through a controlled IAM trust relationship.
This approach demonstrates how deployment automation and security can work together.
Although this example focuses on a simple static website, the underlying concepts can be extended to more advanced architectures involving containers, serverless applications, infrastructure automation, and multi-environment deployment strategies.
The key takeaway is simple: a deployment pipeline should do more than publish code. It should make software delivery repeatable, controlled, secure, and easier to maintain.
---
References
The following official documentation provides additional technical guidance:
AWS Documentation
GitHub Documentation
- "GitHub Actions Documentation" ( https://docs.github.com/en/actions ) - "Configuring OpenID Connect in Amazon Web Services" ( https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-aws ) - "AWS Configure Credentials Action" ( https://github.com/aws-actions/configure-aws-credentials )
---
Suggested Tags: AWS, DevOps, GitHub Actions, CI/CD, Amazon S3, Amazon CloudFront, IAM, OIDC, Automation, Cloud Computing
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article