Email Address
chris@expertcloud.co
Contact Number
+61417725999
Work Hours
Monday to Friday: 7AM - 5PM
Weekend: Closed
In the ever-evolving landscape of web development, there’s a growing trend toward static website hosting for improved performance, security, and cost-efficiency. In this article, we’ll explore a real-world infrastructure setup that leverages Static WordPress with CloudFront to host content generated from WordPress. This approach combines the user-friendly content management capabilities of WordPress with the speed and scalability benefits of static site hosting on AWS CloudFront.
Fun fact: The very blog you’re reading right now, along with the entire expertcloudandai website, is powered by this exact Static WordPress with CloudFront architecture! As you navigate through this site, you’re experiencing firsthand the performance benefits we’ll be discussing.
WordPress powers approximately 43% of all websites on the internet, but traditional WordPress hosting comes with several challenges:
Static site generators solve these problems by pre-rendering all pages as static HTML files. This results in:
But what if you want to keep WordPress as your content management system while enjoying the benefits of static hosting? That’s where the Static WordPress with CloudFront approach comes in, giving you the best of both worlds.
The infrastructure we’re examining uses AWS CloudFormation to create a robust, scalable Static WordPress with CloudFront platform. Here’s the high-level architecture:
Let’s dive deeper into each component and how they work together.
The infrastructure is defined using AWS CloudFormation templates, which provide several advantages:
The project contains three main CloudFormation templates:
expertcloud_infra.yaml
: Defines the S3 and CloudFront resourcesroute53.yaml
: Sets up DNS zones and recordscertificate_stack.yaml
: Creates and validates SSL/TLS certificatesOne critical aspect of this Static WordPress with CloudFront infrastructure is the provisioning of SSL/TLS certificates through AWS Certificate Manager (ACM). An important detail that often trips up developers is that ACM certificates used with CloudFront must be created in the us-east-1 region (N. Virginia), regardless of where the rest of your infrastructure is deployed.
Looking at the GitLab CI/CD pipeline, we can see this requirement is explicitly handled:
deploy_certificate:
# ...
variables:
AWS_DEFAULT_REGION: "us-east-1" # Specifically set to us-east-1
CERTIFICATE_STACK_NAME: "ExpertCloudCertificateStack"
AWS_ROLE_ARN: "arn:aws:iam::xxxxxxxxxxxx:role/GitLabDeploymentRole"
# ...
While the rest of the infrastructure resources (S3 buckets, Route53 configurations) are deployed in ap-southeast-2
(Sydney), the certificate must be provisioned in us-east-1
. The pipeline elegantly handles this multi-region deployment by:
This approach has several advantages:
The pipeline uses environment variables and artifacts to pass information between stages, ensuring that the certificate’s ARN is available when deploying the CloudFront distribution:
CERT_ARN=$(aws cloudformation describe-stacks \
--stack-name "$CERTIFICATE_STACK_NAME" \
--query 'Stacks[0].Outputs[?OutputKey==`CertificateArn`].OutputValue' \
--output text)
echo "CERT_ARN=$CERT_ARN" >> certificate.env
This certificate is then used in the CloudFront distribution configuration:
ViewerCertificate:
AcmCertificateArn: !Ref CertificateArn
SslSupportMethod: sni-only
MinimumProtocolVersion: TLSv1.2_2021
This is the workflow:
website_content/
directoryPopular tools for generating static files from WordPress include:
These tools crawl your WordPress site and generate a complete static version while maintaining URLs, links, and assets, making them perfect for a Static WordPress with CloudFront implementation.
The .gitlab-ci.yml
file defines a comprehensive CI/CD pipeline with five stages:
The most interesting stage for our discussion is deploy_content
, which synchronizes the static website files to the S3 bucket:
deploy_content:
# ...configuration omitted...
script:
- S3_BUCKET=$(aws cloudformation describe-stacks \
--stack-name "$CFN_STACK_NAME" \
--query 'Stacks[0].Outputs[?OutputKey==`S3BucketName`].OutputValue' \
--output text)
- echo "Syncing website content to S3..."
- SYNC_OUTPUT=$(aws s3 sync website_content/ s3://$S3_BUCKET/ --delete --size-only 2>&1)
# Creates CloudFront invalidation if files changed
This script:
The infrastructure includes several optimizations for the CloudFront distribution in this Static WordPress with CloudFront setup:
index.html
to directory requestsA notable feature of this Static WordPress with CloudFront infrastructure is its support for multiple domains:
Each domain (including www subdomains) points to the same CloudFront distribution, allowing for a unified content delivery strategy across multiple brand domains.
By using static WordPress exports with AWS CloudFront, this infrastructure achieves:
While this Static WordPress with CloudFront approach offers many benefits, there are some challenges to consider:
One of the most interesting aspects of this project was the development approach itself. The CloudFormation templates, CI/CD pipeline, and documentation were developed using Cursor IDE with Claude-3.7 Sonnet AI assistance. This combination dramatically accelerated the development process while maintaining high code quality.
The entire infrastructure was coded in a fraction of the time it would traditionally take, thanks to the capabilities of Large Language Models (LLMs) like Claude-3.7 Sonnet. Here’s how LLMs enhanced the development process:
For example, the CloudFront Function to handle directory indexes—a component that would typically require careful testing and refinement—was generated in minutes with proper error handling and edge cases already considered.
While our team leveraged public LLM tools for this project, enterprises with sensitive data or regulatory requirements can achieve similar benefits with proper implementation strategies:
The entire infrastructure described in this article—from initial design to fully functioning CI/CD pipeline—was developed in approximately 2 days rather than the 2-3 weeks it would typically require. This represents an estimated 85% reduction in development time without compromising quality or security.
This acceleration is particularly valuable for enterprises in several ways:
Organizations that successfully implement LLM-assisted development while respecting their data protection and regulatory requirements are positioned to achieve significant competitive advantages through this kind of development acceleration.
The Static WordPress with CloudFront infrastructure examined in this article represents a powerful approach to modern web hosting. By combining the content management capabilities of WordPress with the performance and security benefits of static hosting on AWS CloudFront, it offers the best of both worlds.
This architecture is particularly well-suited for content-heavy websites that don’t require extensive dynamic functionality. For businesses looking to improve website performance, reduce hosting costs, and enhance security, the Static WordPress with CloudFront approach demonstrated by this codebase provides an excellent blueprint to follow.
As mentioned at the beginning, this isn’t just theoretical—the very website you’re browsing right now (expertcloudandai.com) uses this exact infrastructure! Our team manages content through WordPress for its excellent editorial workflow, exports it as static HTML, and deploys it through the automated pipeline described in this article. The result? A blazing-fast, secure, and highly available website that costs a fraction of traditional WordPress hosting to maintain.
Whether you’re managing a corporate website, a blog, or an e-commerce site, consider how static exports from WordPress combined with CloudFront distribution might benefit your digital presence. And if you’re looking to accelerate your own infrastructure development, consider how AI-assisted development might transform your team’s productivity.
You can find all the code for this solution in our GitLab repository.