Skip to content

Commit

Permalink
[ECO-2152] Segment REST and WS endpoints for dual load balancer schema (
Browse files Browse the repository at this point in the history
  • Loading branch information
alnoki authored Sep 4, 2024
1 parent 54f46dd commit d2b1197
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 172 deletions.
144 changes: 84 additions & 60 deletions src/cloud-formation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ using the [template file] at `indexer.cfn.yaml` and a development-specific
[stack deployment file] at `deploy-*.yaml`. Once a [stack] is configured
accordingly, `git` updates will result in automatic updates.

The indexer provides a public endpoint for both REST queries and WebSocket
events at a custom subdomain under a root domain you provide, of format
`<ENVIRONMENT.data.<YOUR_ROOT_DOMAIN>`, for example `dev.data.foo.bar`.
The indexer provides a public REST endpoint and a public WebSocket endpoint
under a root domain you provide, for an environment name of your choosing:

| Endpoint | URI |
| --------- | ------------------------------------------- |
| REST | `https://<ENVIRONMENT>.<YOUR_ROOT_DOMAIN>` |
| WebSocket | `wss://ws.<ENVIRONMENT>.<YOUR_ROOT_DOMAIN>` |

## Template parameters

Expand Down Expand Up @@ -232,39 +236,46 @@ deployment environment:
echo $STACK_NAME
```

1. Get the DNS name specified in the [template outputs section]:
1. Get the endpoints specified in the [template outputs section]:

```sh
DNS_NAME=$(aws cloudformation describe-stacks \
REST_ENDPOINT=$(aws cloudformation describe-stacks \
--output text \
--query 'Stacks[0].Outputs[?OutputKey==`RestEndpoint`].OutputValue' \
--stack-name $STACK_NAME
)
WS_ENDPOINT=$(aws cloudformation describe-stacks \
--output text \
--query 'Stacks[0].Outputs[?OutputKey==`DnsName`].OutputValue' \
--query 'Stacks[0].Outputs[?OutputKey==`WsEndpoint`].OutputValue' \
--stack-name $STACK_NAME
)
echo $DNS_NAME
echo $REST_ENDPOINT
echo $WS_ENDPOINT
```

1. Wait until the DNS name has resolved:
1. Wait until the DNS names have resolved:

```sh
host $DNS_NAME
host $(echo $REST_ENDPOINT | sed 's|^.*//||')
host $(echo $WS_ENDPOINT | sed 's|^.*//||')
```

1. Connect to the WebSocket endpoint:
1. Query the REST endpoint:

```sh
websocat wss://$DNS_NAME/ws
curl "$REST_ENDPOINT/processor_status?select=last_success_version"
```

1. Subscribe to all events:
1. Connect to the WebSocket endpoint:

```sh
{}
websocat $WS_ENDPOINT
```

1. Check PostgREST:
1. Subscribe to all events:

```sh
curl "https://$DNS_NAME/processor_status?select=last_success_version"
{}
```

### Bastion host connections
Expand All @@ -276,66 +287,79 @@ might want to de-provision then provision the bastion host before running the
below commands, in order to refresh the bastion host [user data] that stores the
URLs of other resources in the stack.

Install the [EC2 Instance Connect CLI]:
1. Install the [EC2 Instance Connect CLI]:

```sh
pip install ec2instanceconnectcli
```
```sh
pip install ec2instanceconnectcli
```

Connect to the bastion host over the [EC2 Instance Connect Endpoint] using your
stack name, for example `emoji-dev`:
1. Connect to the bastion host over the [EC2 Instance Connect Endpoint] using
your stack name, for example `emoji-dev`:

```sh
STACK_NAME=emoji-dev
INSTANCE_ID=$(aws cloudformation describe-stacks \
--output text \
--query 'Stacks[0].Outputs[?OutputKey==`BastionHostId`].OutputValue' \
--stack-name $STACK_NAME
)
if [ -n "$(echo -e "${INSTANCE_ID}" | tr -d '[:space:]')" ]; then
echo "Connecting to instance ${INSTANCE_ID}"
aws ec2-instance-connect ssh \
--instance-id $INSTANCE_ID --connection-type eice
else
echo 'Error: instance ID not found or is empty.' >&2
fi
```
```sh
STACK_NAME=emoji-dev
INSTANCE_ID=$(aws cloudformation describe-stacks \
--output text \
--query 'Stacks[0].Outputs[?OutputKey==`BastionHostId`].OutputValue' \
--stack-name $STACK_NAME
)
if [ -n "$(echo -e "${INSTANCE_ID}" | tr -d '[:space:]')" ]; then
echo "Connecting to instance ${INSTANCE_ID}"
aws ec2-instance-connect ssh \
--instance-id $INSTANCE_ID --connection-type eice
else
echo 'Error: instance ID not found or is empty.' >&2
fi
```

Start `psql`:
1. Start `psql`:

```sh
psql $DB_URL
```
```sh
psql $DB_URL
```

List the databases:
1. List the databases:

```sh
\list
```
```sh
\list
```

After exiting `psql`, to view WebSocket events published by the processor:
1. After exiting `psql`, to view WebSocket events published by the processor:

```sh
websocat $PROCESSOR_WS_URL
```
```sh
websocat $PROCESSOR_WS_URL
```

1. Subscribe to all events:

```sh
{}
```

1. Connect to the broker:

```sh
websocat $BROKER_WS_URL
```

Connect to the broker:
1. Subscribe to all events:

```sh
websocat $BROKER_WS_URL
```
```sh
{}
```

Subscribe to all events:
1. Query PostgREST:

```sh
{}
```
```sh
curl $POSTGREST_URL/processor_status?select=last_success_version && echo
```

Query PostgREST:
1. Check PostgREST through the NLB:

```sh
curl $POSTGREST_URL/market_latest_state_event?select=market_id && echo
```
```sh
curl http://$NLB_DNS_NAME:3000/processor_status?select=last_success_version \
&& echo
```

## Design notes

Expand Down
30 changes: 17 additions & 13 deletions src/cloud-formation/deploy-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
---
parameters:
BrokerImageVersion: '0.3.0'
BrokerImageVersion: '0.7.0'
Environment: 'dev'
MaybeDeployAlb: 'false'
MaybeDeployAlbDnsRecord: 'false'
MaybeDeployBastionHost: 'false'
MaybeDeployBroker: 'false'
MaybeDeployContainers: 'false'
MaybeDeployDb: 'false'
MaybeDeployPostgrest: 'false'
MaybeDeployProcessor: 'false'
MaybeDeployRouteTables: 'false'
MaybeDeployStack: 'false'
MaybeDeployVpc: 'false'
MaybeDeployAlb: 'true'
MaybeDeployAlbDnsRecord: 'true'
MaybeDeployBastionHost: 'true'
MaybeDeployBroker: 'true'
MaybeDeployContainers: 'true'
MaybeDeployDb: 'true'
MaybeDeployNlb: 'true'
MaybeDeployNlbVpcLink: 'true'
MaybeDeployPostgrest: 'true'
MaybeDeployProcessor: 'true'
MaybeDeployRestApi: 'true'
MaybeDeployRestApiDnsRecord: 'true'
MaybeDeployRouteTables: 'true'
MaybeDeployStack: 'true'
MaybeDeployVpc: 'true'
Network: 'testnet'
ProcessorImageVersion: '0.4.0'
ProcessorImageVersion: '0.5.0'
tags: null
template-file-path: 'src/cloud-formation/indexer.cfn.yaml'
...
Loading

0 comments on commit d2b1197

Please sign in to comment.