# Amazon EC2 Deploy your Mastra applications to Amazon EC2 (Elastic Cloud Compute). This guide assumes your Mastra application has been created using the default `npx create-mastra@latest` command. For more information on how to create a new Mastra application, refer to our [getting started guide](https://mastra.ai/guides/getting-started/quickstart/llms.txt) ## Prerequisites - An AWS account with [EC2](https://aws.amazon.com/ec2/) access - An EC2 instance running Ubuntu 24+ or Amazon Linux - A domain name with an A record pointing to your instance - A reverse proxy configured (e.g., using [nginx](https://nginx.org/)) - SSL certificate configured (e.g., using [Let's Encrypt](https://letsencrypt.org/)) - Node.js 22.13.0 or later installed on your instance ## Deployment Steps 1. Connect to your EC2 instance and clone your repository: ```bash git clone https://github.com//.git ``` ```bash git clone https://:@github.com//.git ``` Navigate to the repository directory: ```bash cd "" ``` 2. Install dependencies: ```bash npm install ``` ```bash pnpm install ``` ```bash yarn install ``` ```bash bun install ``` 3. Create a `.env` file and add your environment variables: ```bash touch .env ``` Edit the `.env` file and add your environment variables: ```bash OPENAI_API_KEY= # Add other required environment variables ``` 4. Build the application: ```bash npm run build ``` 5. Run the application: ```bash node --env-file=".env" .mastra/output/index.mjs ``` Your Mastra application will run on port 4111 by default. Ensure your reverse proxy is configured to forward requests to this port. ## Connect to your Mastra server You can now connect to your Mastra server from your client application using a `MastraClient` from the `@mastra/client-js` package. Refer to the [`MastraClient` documentation](https://mastra.ai/reference/client-js/mastra-client/llms.txt) for more information. ```typescript import { MastraClient } from "@mastra/client-js"; const mastraClient = new MastraClient({ baseUrl: "https://", }); ``` ## Next steps - [Mastra Client SDK](https://mastra.ai/reference/client-js/mastra-client/llms.txt)