This blog is created using Hakyll and in this post we will see how to setup the hakyll development environment using nix and deploy the website on to Amazon s3 and also on how to deploy website on Amazon EC2 instance.
In my previous post i have mentioned about that nix can be used to setup a development environment, we will see the same in this post.
Hakyll is a Haskell library for generating static sites. static sites are fast, secure and easy to deploy.
In my previous post i have mentioned about that nix can be used to setup a development environment, test a package without installing it using nix-shell. This can be done using
nix-shell -p haskellPackages.hakyll
this command downloads Hakyll and it’s dependencies and then drops you into a shell where ‘hakyll-init’ is available.
generate website using
use cabal2nix to genearate nix build instructions from a cabal file
cabal2nix --shell ./. > default.nix
cabal buildto build the sources
./dist/build/site/site watchto look at your server. The default start page would look like below
Deploying on Amazon S3
- create a bucket in Amazon s3.
- enable static hosting as shown in the below image and select index.html as the starting page
- copy the files generated in _site folder to the bucket.
- access the bucket url to view the start page
Deploying on Amazon EC2 with NGINX webserver
Amazon offers free and paid software products that run on AWS Free Tier. Before proceeding do have a look at Free Tier Limits before hosting your application.
To host on a free tier - login to AMAZON CONSOLE and select EC2 service
- view the ec2 limits for various regions by going to ec2 dashboard and selecting Limits as shown below. for deploying using free tier, check if your region has limits for t2 micro instance. if it is 0 try to change the region or request customer care for an increase in limit.
- create a EC2 t2.micro instance by launching ec2 instance
Provide Tag Name in Step 5
Launch the EC2 instance
install and configure the webserver
copy the files located in _site folder from local machine to remote web server folder using scp, alternatively you can use a source control manager like svn or git to manager your sources.
access the server using public ip address
if you want to access website using domain name , you can purchase a domain on amazon or you can go for Amazon Elastic IPs.
one can assign a static elastic public ip address to a running ec2 instance. aws provides upto 5 elastic ip address and you would be charged if the allocated ip is not assigned to the running ec2 instance as public ip address are scarce. you can see the user guide of elastic ip for more details on elastic ip.
To enable HTTPS on your website i would recommend to use Cert Bot.