---
title: "Discussion on \"How to run Typesense search in AWS\" | Hashnode"
description: "Discussion on \"How to run Typesense search in AWS\". Get Typesense search running within minutes in AWS using infrastructure as code."
url: "https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to run Typesense search in AWS](https://blog.stefanolaru.com/how-to-run-typesense-search-in-aws?utm_source=hashnode&utm_medium=feed)

Get Typesense search running within minutes in AWS using infrastructure as code.

Dec 15, 2022 · 9 min read · blog.stefanolaru.com  
Updated Dec 19, 2022  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#cloudformation](https://hashnode.com/tag/cloudformation)
-   [#typesense](https://hashnode.com/tag/typesense)
-   [#infrastructure](https://hashnode.com/tag/infrastructure)
-   [#search](https://hashnode.com/tag/search)

## Written by

[Stefan Olaru](https://hashnode.com/@stefanolaru)

@stefanolaru

  
[View profile](https://hashnode.com/@stefanolaru)

Head of Development | Architect | 7x AWS Certified | AWS Community Builder | Serverless

An architect by trade, practicing architecture in the Cloud. 7x AWS Certified, AWS Community Builder, Serverless advocate, Vue enthusiast.

## Responses 4

Markdown supported · ⌘↵ to post

[Mateusz Pytinski](https://hashnode.com/@lordpotato89)

[Apr 1, 2024](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/660afcb5a3b15861dd364138)

Hi Stefan,

First, thank you for the template. I am a complete newbie to the topic. I created an AWS server instance via the template and upon connecting to it, i have trouble to even find the typsense application itself under the ./typsense-server, the folder doesnt exist. Any ideas why?

Help would be greatly appreciated.

Regards

[Pancham](https://hashnode.com/@backchap)

[Jan 1, 2024](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/6592a096bb9e53e89c9da855)

Hello, can you use Launch Template instead of Launch Configuration

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Jan 1, 2024](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/6592a096bb9e53e89c9da855#reply-6592a93cbb9e53e89c9e0f4f)

Yes, using Launch Template is recommended now by AWS, however, at the time of writing, I chose to use LC.

[Calvin Butler](https://hashnode.com/@ckcalbut)

[Sep 26, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/65124661555a1a5049a9df3a)

I appreciate your post. Thank you. I have one concern:  
It seems like half of the UserData bash script should be part of the CFN code instead. Specifically these steps should all be in CFN so that CloudFormation can track the resources, no?:

```
# get instance-id
# associate the Elastic IP address to the instance
# attach volume
# wait for volume to be properly attached
# format the volume if doesn't have file system
# create mount root folder
# mount the volume to folder
```

[Calvin Butler](https://hashnode.com/@ckcalbut)

[Sep 27, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/65124661555a1a5049a9df3a#reply-65145ad65d5d746448ea4380)

[Stefan Olaru](https://hashnode.com/@stefanolaru) Certainly!

[Calvin Butler](https://hashnode.com/@ckcalbut)

[Oct 1, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/65124661555a1a5049a9df3a#reply-6519ae766b3bc781290706cf)

[Stefan Olaru](https://hashnode.com/@stefanolaru) Took a me a while (converted to cdk and changed/added some things), but here is what I did to generate the bootstrap api key and startup the typesense instance:

Have AWS Secretsmanager generate the bootstrap api key without it ever touching my laptop:

```
typesense_bootstrap_api_key = secretsmanager.Secret(self, "TypesenseBootstrapAPIKeySecret",
secret_name="TypesenseBootstrapAPIKey",
generate_secret_string=secretsmanager.SecretStringGenerator(
                exclude_uppercase=True,
                exclude_punctuation=True,
                password_length=64,    
            ),
        )
```

Get the Bootstrap API Key from SecretsManager upon execution of the UserData:

```
sudo yum install jq

# get the api key for bootstrapping typesense
secretsmanager_resp=$(aws secretsmanager get-secret-value \
                --secret-id {typesense_bootstrap_api_key.secret_name})
ApiKey=$(echo $secretsmanager_resp | jq -r .SecretString)
```

The Typesense EC2 Instance IAM Role needs additional permissions to get this secret from SecretsManager. I created a SecretsManagerReadOnlyPolicy and attached it to the role:

```
secrets_manager_read_only_policy = iam.ManagedPolicy(self, "SecretsManagerReadOnlyPolicy",
            managed_policy_name="SecretsManagerReadOnly",
            statements=[iam.PolicyStatement(
                effect=iam.Effect.ALLOW,
                actions=[
                            "secretsmanager:GetResourcePolicy",
                            "secretsmanager:GetSecretValue",
                            "secretsmanager:DescribeSecret",
                            "secretsmanager:ListSecretVersionIds"
                        ],
                resources=["*"]
            )]
        )
```

I do end up using a lambda function to generate api keys. It gets the bootstrap or admin key (depending on what keyname you pass in the payload) from secretsmanager, reaches out to typesense to generate a new key with whatever name and permissions were passed in the payload, and then stores that new key in secretsmanager. Hopefully this can be run to generate the basic keys I'd want (admin, readwrite, readonly, idk what else) upon CDK deploy, but I don't have a great way to ensure it runs after the typesense server actually starts up for the first time without doing something very hacky.

By the way, my UserData script needed this addition to get the EC2\_INSTANCE\_ID:

```
# get instance-id
TOKEN=$(curl -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 600" "instance-data/latest/api/token")
EC2_INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s instance-data/latest/meta-data/instance-id)
```

This is all built into a greater cdk project I have going, but I will pull this out and put it in a public repo when I have time.

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Oct 2, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/65124661555a1a5049a9df3a#reply-651a69cb6b3bc78129071561)

[Calvin Butler](https://hashnode.com/@ckcalbut) Awesome, thanks for the detailed reply! 👏

[Nick Verwymeren](https://hashnode.com/@greatwitenorth)

[Mar 24, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/641e0446ecc310467c900379)

I used cloudformation, but it look like the IP that is output does not support SSL. Can you provide some insight on how I could support SSL?

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Mar 25, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/641e0446ecc310467c900379#reply-641e93ce05c482464c90b4f2)

Hi Nick, SSL on IP is tricky but you can point a sub/domain to it and install Certbot to issue a free Let's Encrypt certificate.

[Nick Verwymeren](https://hashnode.com/@greatwitenorth)

[Mar 27, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/641e0446ecc310467c900379#reply-6421a816a52e2874dcd069c8)

[Stefan Olaru](https://hashnode.com/@stefanolaru) Thanks for the reply. I've tried that but then I run into issues with the certificate being only readable by root, but the typesense service being run by ec2-user. I get this error on startup:

"An error occurred while trying to load server certificate file: /etc/letsencrypt/live/example.com/fullchain.pem"

I've read that putting a load balancer in front of everything will allow us to install an aws issued certificate. Would you have an example of how to do that?

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Mar 28, 2023](https://hashnode.com/posts/how-to-run-typesense-search-in-aws/639aa5021105b04b6078f283/comment/641e0446ecc310467c900379#reply-64226f95a3c2ab85c4430139)

Hi Nick, you could add an ALB in front of your instance, though for a single instance and just for SSL certificate it might be overkill.

Have a look at my other article about running a multi-node Typesense, it uses a Load Balancer [blog.stefanolaru.com/how-to-run-highly-available-…](https://blog.stefanolaru.com/how-to-run-highly-available-typesense-cluster-in-aws)

Another (free) option would be to install Nginx which will handle the SSL termination and proxy to Typesense. But it's very likely possible to manage this directly from Typesense ...
