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

# Deploy to AWS

> A CloudFormation stack that runs the agent on a small EC2 instance in your own VPC.

The CloudFormation template puts the Observer Agent on a small EC2
instance in a VPC and subnet you choose. From there the agent checks
what that subnet can reach, such as private databases, internal APIs
and Prometheus. It only makes outbound calls: the stack opens no
inbound port. Your cloud's pricing applies to everything the stack
creates.

## What the stack creates

* An EC2 instance named `observer-agent`: Amazon Linux 2023 (arm64),
  `t4g.nano` by default, an encrypted 8 GB gp3 volume, IMDSv2 required.
* A security group with outbound rules only.
* A Secrets Manager secret that holds the agent key. The instance reads
  it at first boot, so the key never appears in the instance user data.
* An IAM role for the instance. It may read that one secret, and it
  carries `AmazonSSMManagedInstanceCore` so you can open a shell with
  Session Manager instead of SSH.

At first boot the instance runs the
[install script](https://docs.use.observer/agent/reference/install-script.md), which installs the
agent binary as the `observer-agent` systemd service.

## Before you start

* Create the agent in Observer: **Agents**, **Add agent**, then
  **Cloud platforms**. Copy the key. Observer shows it once.
* Pick the VPC of the services the agent should check, and a subnet in
  it with outbound internet access. Either:

  * a public subnet, with a public IP (the default), or
  * a private subnet behind a NAT gateway, with the public IP turned
    off.

  The public IP carries outbound traffic only. Nothing listens on it.
* Deploy in the region of that VPC.

To list the subnets of a VPC:

```bash theme={null}
aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-0123456789abcdef0 \
  --query "Subnets[].[SubnetId,AvailabilityZone,CidrBlock]" --output table
```

## Parameters

| Parameter | Console label | Default | Notes |
| - | - | - | - |
| `AgentKey` | Agent key | | The key from Observer (`obs_live_...`). Hidden in the console and stored in Secrets Manager. |
| `CloudServerUrl` | Observer address | `https://use.observer` | Leave as is. |
| `VpcId` | VPC | | The VPC of the services to check. |
| `SubnetId` | Subnet | | A subnet in that VPC with outbound internet access. |
| `AssignPublicIp` | Public IP for outbound traffic | `true` | `true` in a public subnet, `false` in a private subnet behind a NAT gateway. |
| `InstanceType` | Instance type | `t4g.nano` | `t4g.nano`, `t4g.micro` or `t4g.small`. The agent is small; `t4g.nano` is enough for most setups. |
| `LatestAmiId` | Image | latest Amazon Linux 2023 arm64 | Leave as is. |

## Deploy with the AWS CLI or CloudShell

**1. Download the template**

```bash theme={null}
curl -fsSLO https://raw.githubusercontent.com/useobserver/agent/main/deploy/aws/observer-agent.yaml
```

**2. Create the stack**

```bash theme={null}
aws cloudformation deploy --stack-name observer-agent \
  --template-file observer-agent.yaml --capabilities CAPABILITY_IAM \
  --parameter-overrides AgentKey="obs_live_..." \
    VpcId=vpc-xxxxxxxx SubnetId=subnet-xxxxxxxx
```

In a private subnet behind a NAT gateway, add `AssignPublicIp=false`
to the overrides. Add `--region <region>` when the VPC is not in your
default region. `CAPABILITY_IAM` lets the stack create the instance
role. The command waits until the stack is created.

## Deploy from the AWS console

There is no Launch Stack button yet. Upload the template instead:

**1. Download the template**

Save
[observer-agent.yaml](https://raw.githubusercontent.com/useobserver/agent/main/deploy/aws/observer-agent.yaml)
to your computer.

**2. Create the stack**

Open CloudFormation in the region of your VPC and choose
**Create stack**, **With new resources (standard)**. Keep **Choose an
existing template**, then pick **Upload a template file**, select
`observer-agent.yaml` and choose **Next**.

**3. Fill in the parameters**

Name the stack (for example `observer-agent`). Paste the key into
**Agent key**, then pick the **VPC** and the **Subnet**. For a private
subnet behind a NAT gateway, set **Public IP for outbound traffic** to
`false`. Choose **Next**, keep the stack options, and choose **Next**
again.

**4. Create it**

Tick the acknowledgement that CloudFormation might create IAM
resources, then choose **Submit**. The stack reaches
`CREATE_COMPLETE` in a few minutes.

## Check that it connected

A few minutes after the stack completes, the Add agent screen shows
**Connected** and the Agents page marks the agent as **running**. The
instance first boots, then downloads and installs the agent.

If it does not connect, read the agent's logs. The stack's `Logs`
output holds the command:

```bash theme={null}
aws cloudformation describe-stacks --stack-name observer-agent \
  --query "Stacks[0].Outputs" --output table
```

Open a shell on the instance with Session Manager: in the EC2 console
select the instance, then **Connect**, **Session Manager**,
**Connect**. From the AWS CLI with the Session Manager plugin
installed:

```bash theme={null}
aws ssm start-session --target i-0123456789abcdef0
```

Then:

```bash theme={null}
sudo journalctl -u observer-agent -f
```

The agent logs every failed call to Observer with the reason. The most
common cause is a wrong or replaced agent key. If the
`observer-agent` service does not exist, the install at first boot
failed: its output is in `/var/log/cloud-init-output.log`. The usual
cause is a subnet without outbound internet access, which also stops
Session Manager from connecting.

## Add settings and secrets

The agent reads its environment from `/etc/observer-agent/agent.env`.
To add a variable, such as `PROMETHEUS_SERVER_URL` or a secret that a
probe references by name (`connection_string_ref` and the like), edit
the file and restart the service:

```bash theme={null}
sudo vi /etc/observer-agent/agent.env
sudo systemctl restart observer-agent
```

After a [key rotation](https://docs.use.observer/agent/guides/rotate-agent-key.md), put the new
key in `AGENT_KEY` in the same file. Updating the stack's `AgentKey`
parameter does not reach a running instance: the instance reads the
secret only at first boot. See
[Environment variables](https://docs.use.observer/agent/reference/environment-variables.md) for
every setting.

## Upgrades

The stack installs the agent binary with the install script. To
upgrade, run the script again from a Session Manager shell. It
replaces the binary, restarts the service, and keeps the key and your
settings:

```bash theme={null}
curl -fsSL https://use.observer/install.sh | sh
```

To install a given release, add `-s -- --version <X.Y.Z>` after `sh`.

## Remove

```bash theme={null}
aws cloudformation delete-stack --stack-name observer-agent
```

Or select the stack in the CloudFormation console and choose
**Delete**. Deleting the stack deletes everything it created: the
instance and its volume, the security group, the role and the secret.
Delete the agent in Observer (**Agents**) too if you no longer need
it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.