Setting up TiTiler to serve COGs of UAV imagery on AWS with leaflet and Elastic Beanstalk
aws
s3
s3sf
leaflet
COG
titiler
Author
al
Published
January 17, 2025
Modified
January 19, 2025
Whoa Bobby-Joe.
Journey here to set up a TiTiler on a remote server.
This is a continuation of a past post that you can find here. Thanks to ChatGPT for the help. Image by ChatGPT.
We want a tile service to render Cloud Optimized Geotiffs (Cogs) in the browser using server side rendering. For that we need something like TiTiler running on a cloud instance. So we’re gonna document that set up on AWS here so we can find it again.
To enable scalability and simplify deployment we will use AWS Elastic Beanstalk (eb). We are on a mac so first thing we do is:
brew install a WSEBCLI.
Because we are already set up with credentials through environmental variables back when we set up awsclieb will link to those credentials automatically on initialization.
So next we need to identify a launch template for the eb environment as per these docs
First thing is to find the latest Amazon Linux 2 AMI ID:
aws ec2 describe-security-groups --group-names titilersecuritygroup --query "SecurityGroups[0].GroupId" --output text
Update the Launch Template: Add the Security Group ID to the Launch Template using its LaunchTemplateId:
Then we make a litle launchtemplate.config file and put it in our main project directory elastic-beanstock in a .ebextensions directory. It looks like this with our SecurityGroups id added as per our last query:
In order to have an easy launch of Titiler we make a Dockerrun.aws.json file to go in our main elastic-beanstock roject directory we have created to do this work. The Dockerrun.aws.json file looks like this:
aws iam attach-role-policy --role-name aws-elasticbeanstalk-service-role \
--policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess
To be sure - we verify the policy is attached:
aws iam list-attached-role-policies --role-name aws-elasticbeanstalk-service-role
You should see AmazonEC2FullAccess in the output.
Verify the VPC. A VPC (Virtual Private Cloud) is a private, isolated network within AWS where you can launch and manage AWS resources like EC2 instances, databases, and load balancers. Run this command to see the route tables for each subnet and determine if they are public:
aws ec2 describe-vpcs --query "Vpcs[?IsDefault].VpcId" --region us-west-2 --output text
Next it gets weird - Find the Default Route Table with a query that includes our uniqye VpcId which we recieved from our last query:
Because the default route table is connected to an Internet Gateway - subnets need to be explicitly associated with this route table. Look for entries with “DestinationCidrBlock”: “0.0.0.0/0” and “GatewayId”: “igw-xxxxxxxx” in the output. These indicate that the subnet is public.; those without are private:
Once that is completed we can find our Elastic Beanstalk environment’s CNAME with:
eb status
Here is what our setup file structure looks like.
Code
# Its `CNAME: titiler-env.eba-s4jhubvr.us-west-2.elasticbeanstalk.com`fs::dir_tree("/Users/airvine/Projects/repo/elastic-beanstalk", recurse =TRUE, all =TRUE)