Tiny Twitter API Infra

This project provisions the AWS infrastructure necessary for the Tiny Twitter API.

Prerequisites

  • An AWS account.
  • SSH keys generated locally.
  • Visual Studio Code with the Remote - Containers extension installed.

Initial Setup

  1. Set Up AWS Credentials

    Firstly, rename the file devcontainer.env.sample to devcontainer.env in the .devcontainer directory. Then, replace the values of the following variables with your AWS credentials:

AWS_DEFAULT_REGION=<your_aws_default_region>
AWS_PROFILE=<your_aws_profile>
AWS_ACCESS_KEY_ID=<your_aws_access_key_id>
AWS_SECRET_ACCESS_KEY=<your_aws_secret_access_key>

Note: Never commit devcontainer.env to source control. This is sensitive information.

  1. Generate Local SSH Keys

To generate an SSH key pair for your EC2 instance, run:

ssh-keygen -t rsa -b 4096 -f ./ssh/tiny-twitter-api-key
  1. Launch the Development Container

To use the development container, you'll need to have both Visual Studio Code and the Remote - Containers extension installed. Here's a step-by-step guide:

  1. Install Visual Studio Code: If you haven't installed Visual Studio Code, you can download it from here.

  2. Install the Remote - Containers Extension: Inside Visual Studio Code, navigate to the Extensions view by clicking on the square icon on the sidebar or pressing Ctrl+Shift+X. Search for "Remote - Containers" and install it.

  3. Open the Project in VS Code: Navigate to the location of your project in your file system. Right-click within the folder and select "Open with Visual Studio Code."

  4. Open the Project in a Dev Container: Once inside VS Code:

  • Press Ctrl+Shift+P or Cmd+Shift+P on Mac to open the command palette.
  • Type "Remote-Containers: Open Folder in Container..." and select it.
  • Choose the project folder, and VS Code will start building the development container. This process may take a few minutes the first time.
  1. Working Inside the Dev Container: Once the container is up and running, you'll notice the bottom-left corner of VS Code indicates that you're working inside the container. You can now run any command inside this isolated environment.

Provision the Infrastructure

Please note: Deploying some infrastructure components on AWS will lead to charges on your AWS account. Before applying Terraform configurations, it's recommended to use tools like Infracost to estimate potential costs.

Inside your development container, and within the main directory, follow these steps:

  1. Initialize Terraform:
 terraform init
  1. Review planned changes:
terraform plan
  1. Apply changes:
 terraform apply

Once the infrastructure setup is complete, you can access the application using the IP address provided in the output: http://<ip_address>. You can also, access the EC2 instance using the following command:

ssh -i ~/.ssh/tiny-twitter-api-key ubuntu@<ip_address>
  1. Destroy the infrastructure:

You can destroy the infrastructure anytime by running:

terraform destroy