> ## 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.

# fjall add

> Add AWS resources (database, compute, storage, CDN) to an existing Fjall application and update its CDK code.

<Info>
  `fjall add` edits an application's `infrastructure.ts` through the codemod engine. It does not deploy. Run `fjall deploy` afterwards to apply changes to AWS.
</Info>

## Overview

`fjall add` appends a resource to an existing application's `infrastructure.ts`. It writes valid CDK code, wires connections to existing resources, and reports the lines changed. The command runs the codemod engine directly in both human and agent modes. There is no interactive resource picker on this path.

## Usage

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

| Token                        | Meaning                                                                         |
| ---------------------------- | ------------------------------------------------------------------------------- |
| `<type>`                     | Required. The resource category (see [Resource Types](#resource-types)).        |
| `--app <app>`                | Required. The application to edit.                                              |
| `--name <Name>`              | Required. Resource name in PascalCase.                                          |
| `[--<property> <value> ...]` | Optional. Resource-specific configuration as repeated `--<name> <value>` pairs. |

## Resource Types

`<type>` is one of these exact values:

| Type                    | Adds                                                                              |
| ----------------------- | --------------------------------------------------------------------------------- |
| `database`              | A managed database (Aurora, RDS instance, GlobalAurora, ClickHouse, or DynamoDB). |
| `compute`               | A compute service (Lambda, ECS, or EC2).                                          |
| `storage`               | An S3 bucket.                                                                     |
| `cdn`                   | A CloudFront distribution.                                                        |
| `messaging`             | An SQS queue or SNS topic.                                                        |
| `network`               | A network resource.                                                               |
| `pattern`               | A higher-level pattern composition.                                               |
| `vpc-peer`              | A VPC peering requester.                                                          |
| `vpc-peer-accepter`     | A VPC peering accepter.                                                           |
| `cross-plan-connection` | A connection to a resource in another application.                                |

<Note>
  There is no `proxy` or `service` type, and there is no colon syntax. A database variant, RDS proxy, or additional ECS service is configured with property flags, not a separate type. `fjall add database:Aurora` is invalid.
</Note>

### Property flags

Every flag after `--app`, `--name`, `--verbose`, and `--non-interactive` is a resource property, parsed as a `--<name> <value>` pair. Three rules apply:

1. Each flag consumes the next token as its value. A trailing flag with no value is rejected.
2. A flag immediately followed by another `--flag` is rejected (no value-less booleans). Pass an explicit value such as `--require-tls true`.
3. Duplicate flags are rejected so typos surface instead of being silently overwritten.

## Examples

### Add a database

`database` is always the type. Choose the variant with the `--type` property (`Aurora`, `Instance`, `GlobalAurora`, `ClickHouse`, or `DynamoDB`):

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

The codemod emits `DatabaseFactory.build("Analytics", { type: "Aurora", ... })`.

### Add a compute service

```bash theme={null}
# Lambda function
fjall add compute --app api --name OrderProcessor --type lambda

# ECS service on Fargate Spot for cost savings
fjall add compute --app api --name Worker --type ecs --capacity-provider FARGATE_SPOT
```

### Add a storage bucket

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

### Add a CDN distribution

```bash theme={null}
fjall add cdn --app web --name Assets
```

### Restore a database from a snapshot

Pass the snapshot details as property flags. The master username is baked into the snapshot:

```bash theme={null}
fjall add database --app api --name Restored --type Instance \
  --snapshot-identifier rds:my-production-snapshot \
  --snapshot-username postgres
```

<Warning>
  The master username is immutable and baked into the snapshot. It must match the original database's username exactly.
</Warning>

### Add an RDS proxy

A proxy is a property of a database resource, configured with property flags such as `--proxy` and `--max-connections`:

```bash theme={null}
fjall add database --app api --name Sessions --type Instance \
  --proxy true \
  --max-connections 50 \
  --require-tls true
```

## Options

These are the only flags the `add` command registers. Everything else is a property flag.

| Option              | Description                                    |
| ------------------- | ---------------------------------------------- |
| `-a, --app <name>`  | Application to add the resource to (required). |
| `-n, --name <name>` | Resource name in PascalCase (required).        |
| `-v, --verbose`     | Enable verbose logging.                        |
| `--non-interactive` | Force plain CLI output (no UI).                |

### Agent options

For AI-agent and scripted use, `add` also accepts the standard agent flags:

| Option              | Description                             |
| ------------------- | --------------------------------------- |
| `--agent`           | Emit machine-readable agent output.     |
| `--budget <level>`  | Output verbosity budget for agent mode. |
| `--fields <fields>` | Restrict the output to named fields.    |
| `--full`            | Include the full result payload.        |

## Non-Interactive Mode

For CI/CD pipelines, pass `--non-interactive` with all required flags so no prompt is reached:

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

# Lambda function
fjall add compute --app api --name Worker --type lambda --non-interactive

# ECS service on Fargate Spot
fjall add compute --app api --name Api --type ecs \
  --capacity-provider FARGATE_SPOT --non-interactive
```

## Connection Management

When adding a resource, Fjall detects existing resources, configures security groups, and sets environment variables on connected compute.

Connected resources receive automatic environment variables:

```bash theme={null}
# First database connection
DATABASE_HOST=app-db.cluster-xxx.amazonaws.com
DATABASE_PORT=35255
DATABASE_NAME=AppDatabase
DATABASE_PASSWORD=<from-secrets-manager>

# Additional database connections
DATABASE_HOST_1=analytics-db.cluster-xxx.amazonaws.com
DATABASE_PORT_1=35255
DATABASE_NAME_1=AnalyticsDB
DATABASE_PASSWORD_1=<from-secrets-manager>
```

## Add Multiple Resources

Chain commands for a multi-resource setup:

```bash theme={null}
fjall add database --app api --name Analytics --type Aurora
fjall add compute --app api --name Worker --type lambda
fjall add compute --app api --name Api --type ecs
```

## Resource Naming

Resource names are PascalCase and must be unique within the application. Pick descriptive names such as `Analytics`, `Sessions`, or `Uploads` so resources are easy to identify later. If a name conflicts with an existing resource, the codemod reports the conflict instead of overwriting.

## After Adding a Resource

1. Review the modified `infrastructure.ts`.
2. List the application's resources to confirm the change: `fjall list --app api`.
3. Deploy to apply the change to AWS: `fjall deploy api`.

## Next Steps

<CardGroup cols={2}>
  <Card title="fjall deploy" icon="rocket" href="/cli/deploy">
    Apply the new resource to AWS.
  </Card>

  <Card title="fjall list" icon="list" href="/cli/list">
    List the resources in an application's infrastructure.ts.
  </Card>

  <Card title="fjall create" icon="folder-plus" href="/cli/create">
    Create a new application before adding resources to it.
  </Card>

  <Card title="fjall secrets" icon="key" href="/cli/secrets">
    Manage application secrets in AWS.
  </Card>
</CardGroup>
