> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fjall.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Resources

> Add AWS database, compute, storage, and CDN resources to an existing Fjall application.

<AccordionGroup>
  <Accordion icon="book" title="Prerequisites">
    Complete these first:

    * [Deploy Application](/deployment/deploy-application)
    * A deployed Fjall application
  </Accordion>
</AccordionGroup>

***

## Overview

As your application grows, add more resources to its `infrastructure.ts`. The `fjall add` command edits the file through the codemod engine, then `fjall deploy` provisions the change on AWS.

Every `add` follows one shape:

```bash theme={null}
fjall add <type> --app <app> --name <PascalCaseName> [--<property> <value> ...]
```

| Part           | Rule                                                                                                                                         |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `<type>`       | One of: `database`, `storage`, `compute`, `messaging`, `cdn`, `network`, `pattern`, `vpc-peer`, `vpc-peer-accepter`, `cross-plan-connection` |
| `--app`        | The application that owns the `infrastructure.ts` file                                                                                       |
| `--name`       | Required, PascalCase (for example `Analytics`, `WebCdn`)                                                                                     |
| `--<property>` | Optional resource properties, each with a trailing value                                                                                     |

<Note>
  There is no colon syntax. `fjall add database:Aurora` is invalid. The database variant is a property: `fjall add database --type Aurora`.
</Note>

***

## Add a database

Add a database and pick the variant with `--type`:

```bash theme={null}
fjall add database --app api --name Analytics --type Aurora
```

The variant determines the database engine and topology.

| `--type` value | Use case                                     |
| -------------- | -------------------------------------------- |
| `Aurora`       | Aurora Serverless clusters                   |
| `Instance`     | Standard RDS instances                       |
| `GlobalAurora` | Multi-region Aurora clusters                 |
| `ClickHouse`   | Analytics database for high-volume telemetry |
| `DynamoDB`     | Serverless key-value and document store      |

### Multiple databases

An application can hold several databases. Give each a distinct PascalCase name:

```bash theme={null}
# Primary transactional database
fjall add database --app api --name Primary --type Aurora

# Analytics database
fjall add database --app api --name Analytics --type Aurora

# Secondary instance
fjall add database --app api --name Secondary --type Instance
```

### Interactive connection prompt

When you run `fjall add` interactively and existing compute resources are present, the wizard offers to wire the database to them:

```text theme={null}
? Found existing compute resources. Connect this database to them? Yes

? Select services to connect to the database:
  ◉ ApiCompute
  ◯ ApiWorker
```

If exactly one compute target exists, the wizard selects it automatically and skips the multi-select.

***

## Add storage (S3)

Add an S3 bucket:

```bash theme={null}
fjall add storage --app api --name Assets
```

***

## Add compute

The `compute` type covers Lambda functions and ECS services. Pick the variant interactively, or pass it as a property in non-interactive mode.

```bash theme={null}
fjall add compute --app api --name ImageProcessor
```

The wizard prompts for the variant and its settings:

```text theme={null}
? Compute type:
  ❯ Lambda (event-driven function)
    ECS (long-running service)
? Memory (MB): 1024
? Timeout (seconds): 300
? Connect to storage? Yes
```

| Variant | Use case               |
| ------- | ---------------------- |
| Lambda  | Event processing, APIs |
| ECS     | Long-running services  |

***

## Add a CDN

Add a CloudFront distribution:

```bash theme={null}
fjall add cdn --app api --name WebCdn
```

***

## What happens on add

When you add a resource, Fjall configures the supporting wiring automatically:

1. **Security groups** open the required ports
2. **Environment variables** carry connection strings into connected compute
3. **Secrets** hold database passwords in Secrets Manager
4. **IAM roles** receive the permissions the resource needs

### Connection environment variables

Connected compute receives connection details as environment variables. The first database uses unsuffixed names, and additional databases get numbered suffixes:

```bash theme={null}
# First database
DATABASE_HOST=api-db.cluster-xxx.amazonaws.com
DATABASE_PORT=5432
DATABASE_NAME=ApiDatabase
DATABASE_PASSWORD=<from-secrets-manager>

# Additional databases get numbered suffixes
DATABASE_HOST_1=analytics-db.cluster-xxx.amazonaws.com
DATABASE_PORT_1=5432
DATABASE_NAME_1=AnalyticsDB
DATABASE_PASSWORD_1=<from-secrets-manager>
```

***

## Worked examples

### Microservice setup

```bash theme={null}
# API function
fjall add compute --app api --name ApiGateway

# Authentication service
fjall add compute --app api --name AuthService

# User database
fjall add database --app api --name UserDb --type Aurora
```

### Data pipeline

```bash theme={null}
# Data ingestion function
fjall add compute --app api --name DataIngestion

# Processing service
fjall add compute --app api --name DataProcessor

# Data warehouse
fjall add database --app api --name DataWarehouse --type Aurora
```

***

## Non-interactive mode

Pass `--non-interactive` to add a resource without prompts. Supply every required property as a flag:

```bash theme={null}
# Aurora database
fjall add database \
  --app api \
  --name Analytics \
  --type Aurora \
  --non-interactive

# Lambda function
fjall add compute \
  --app api \
  --name Processor \
  --non-interactive
```

***

## Deploy after adding

Adding a resource only edits `infrastructure.ts`. Provision it with a deploy:

```bash theme={null}
fjall deploy api
```

Fjall reports what it will change:

```text theme={null}
Resources to create:
  + AWS::RDS::DBCluster (Analytics)
  + AWS::Lambda::Function (Processor)
  + AWS::EC2::SecurityGroup (2)

Resources to update:
  ~ AWS::ECS::TaskDefinition (environment variables)
```

***

## List resources

`fjall list` reads the resources defined in an application's `infrastructure.ts`. The application is selected with `-a, --app`, and an optional `[type]` positional filters the output:

```bash theme={null}
# All resources in the api application
fjall list --app api

# Databases only
fjall list database --app api
```

```text theme={null}
api:
  Compute:
    - ApiCompute (ECS/Fargate)
    - ImageProcessor (Lambda)
  Database:
    - Primary (Aurora)
    - Analytics (Aurora)
  Storage:
    - Assets (S3)
```

***

## Best practices

| Practice                              | Why                                                                        |
| ------------------------------------- | -------------------------------------------------------------------------- |
| Plan connections                      | Decide which resources need to communicate before adding them              |
| Use descriptive PascalCase names      | Resources stay easy to identify in `infrastructure.ts` and the AWS console |
| Right-size resources                  | Match instance sizes to expected load to control cost                      |
| Add and deploy one resource at a time | Smaller changes are easier to review and roll back                         |

***

## All resource types

| Type      | Command                               | Description                          |
| --------- | ------------------------------------- | ------------------------------------ |
| Database  | `fjall add database --type <variant>` | RDS, Aurora, ClickHouse, or DynamoDB |
| Compute   | `fjall add compute`                   | Lambda function or ECS service       |
| Storage   | `fjall add storage`                   | S3 bucket                            |
| CDN       | `fjall add cdn`                       | CloudFront distribution              |
| Messaging | `fjall add messaging`                 | EventBridge bus or queue             |
| Network   | `fjall add network`                   | Additional VPC network resources     |
| Pattern   | `fjall add pattern`                   | Composed application pattern         |

<Note>
  Add resources at any time. Fjall configures networking and security automatically on the next deploy.
</Note>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Deploy Application" icon="rocket" href="/deployment/deploy-application">
    Provision your updated infrastructure on AWS
  </Card>

  <Card title="Remove Resources" icon="trash" href="/cli/remove">
    Remove a resource from infrastructure.ts
  </Card>
</CardGroup>
