{"id":26123281,"url":"https://github.com/pablotor/aiawsinstace","last_synced_at":"2026-05-01T22:34:22.844Z","repository":{"id":281556879,"uuid":"945128103","full_name":"pablotor/aiAwsInstace","owner":"pablotor","description":"A Terraform configuration for deploying an AI API on an AWS EC2 instance.","archived":false,"fork":false,"pushed_at":"2025-03-09T21:46:45.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T22:27:11.305Z","etag":null,"topics":["ai","ai-api-integration","aws","chatgpt","ollama","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pablotor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-08T18:12:05.000Z","updated_at":"2025-03-09T21:51:06.000Z","dependencies_parsed_at":"2025-03-09T22:37:18.469Z","dependency_job_id":null,"html_url":"https://github.com/pablotor/aiAwsInstace","commit_stats":null,"previous_names":["pablotor/aiawsinstace"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablotor%2FaiAwsInstace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablotor%2FaiAwsInstace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablotor%2FaiAwsInstace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablotor%2FaiAwsInstace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pablotor","download_url":"https://codeload.github.com/pablotor/aiAwsInstace/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242882911,"owners_count":20200974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-api-integration","aws","chatgpt","ollama","terraform"],"created_at":"2025-03-10T15:46:26.057Z","updated_at":"2026-05-01T22:34:22.790Z","avatar_url":"https://github.com/pablotor.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI AWS Instance\n\nAI APIs are great. You can experiment with them, integrate them into your apps, and probably do a bunch of other things I haven’t even started to think about. But there’s a catch: all the ones I found are either paid or have an incredibly low usage limit. So, if you have some AWS credits to burn, this might help you out. And if you don’t, [ask for them!](https://pages.awscloud.com/GLOBAL_NCA_LN_ARRC-program-A300-2023.html)  \n\nThis Terraform setup deploys an EC2 instance with Ollama and all the necessary infrastructure to use the Ollama API from the internet with a basic level of authentication. This is not a production-ready script, but it can be a good starting point.  \n\n## Pre-requisites\n- An AWS account with some funds to burn\n- An AWS user with an appropriate permission policy to manage EC2s instances, VPCs and DNS records\n- [The AWS cli installed and set up](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)\n- [The Terraform cli installed and set up](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli)\n- [An SSH key generated WITHOUT A PASSPHRASE](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)\n- (Optional) Using a custom domain and SSL requires a preconfigured domain in AWS or NS records pointing to corresponding AWS NS servers\n\n## Before deployment\n1. Create your `terraform.tfvars` file from the example:\n  ```bash\n  cp terraform.tfvars.example terraform.tfvars\n  ```\n2. Update the AWS profile, instance names, and both SSH key paths to match yours.\n3. Create your secret.tfvars file from the example:\n  ```bash\n  cp secret.tfvars.example secret.tfvars\n  ```\n4. Generate your API token and append it to secret.tfvars. The key must be enclosed in double quotes:\n  ```bash\n   openssl rand -base64 32\n  ```\n5. Initialize Terraform:\n  ```bash\n    terraform init\n  ```\n\n## How to deploy\nFrom here, it’s all pretty straightforward. The only difference from other Terraform projects is that we’re adding the API key secret manually.\n\n1. List all elements to be deployed:\n  ```bash\n  terraform plan -var-file=\"secret.tfvars\"\n  ```\n2. Then deploy them:\n  ```bash\n  terraform apply -var-file=\"secret.tfvars\"\n  ```\nThe deployment will output your instance public ip. Save it for later.\n\n3. And at some point, destroy them:\n  ```bash\n  terraform destroy -var-file=\"secret.tfvars\"\n  ```\n\n## Testing the deployment\nIf everything went well, you should be able to hit the Ollama API using your API key. Here’s a simple script to test connectivity and functionality from the terminal:\n  ```bash\n  curl http://\u003cinstance_public_ip\u003e/api/chat \\\n    -H \"Authorization: Bearer \u003capi_key\u003e\" -d '{\n      \"model\": \"\u003cselected_model\u003e\",\n      \"messages\": [\n        {\n          \"role\": \"user\",\n          \"content\": \"why is the sky blue?\"\n        }\n      ],\n      \"stream\": false\n    }'\n  ```\n\n## Debugging\nIf your requests aren’t working, you can log into the instance via SSH and check the Ollama and Nginx process statuses and configurations:\n  ```bash\n  ssh -i \u003cssh_private_key_path\u003e ec2-user@\u003cinstance_public_ip\u003e\n  ```\n\n## How to use\nI'm using the [OpenAI Node](https://github.com/openai/openai-node) package to interact with the API because the configuration is quite simple:\n\n```js\nimport OpenAI from 'openai';\n\nconst openai = new OpenAI({\n  baseURL: 'http://\u003cpublic_ip\u003e/api',\n  apiKey: '\u003capi_key\u003e',\n});\n\nasync function main() {\n  const chatCompletion = await client.chat.completions.create({\n    messages: [{ role: 'user', content: 'Say this is a test' }],\n    model: 'tinyllama',\n  });\n}\n\nmain();\n```\n\nEnjoy!\n\n## What's comming\n- User configuration\n- Some proper key management would be nice\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablotor%2Faiawsinstace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpablotor%2Faiawsinstace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablotor%2Faiawsinstace/lists"}