#!/bin/bash
MODE=$1
if [[ -z $2 ]];then HEADTAIL_LIMIT=0; else HEADTAIL_LIMIT=$2;fi
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../.."
source scripts/funcs

echo "## Running task locally with remotely stored configurations

We will continue using 03_exchange_rates example. But this time, we will
store the configurations to the remote data store.
"

Prompt

CheckAws

ChooseAwsProfile

echo "
Let's review how 03_exchange_rates project directory is structured:
"

ListDir "03_exchange_rates"

Prompt

echo "
In the config directory, we have a couple of configuration files:
"
ListDir "03_exchange_rates/config"

Prompt

echo "
...which look like:
"

Cat "03_exchange_rates/config/tap-config.json" $DIM 0

Cat "03_exchange_rates/config/target-config.json" $DIM 0

echo "
Often times, such configuration files contain sensitive information.
So we push the configrations to a secure key store such as
AWS Systems Manager (SSM) Parameter Store (In SecuresString format)
handoff wraps this proces by a single command. handoff packs all the JSON
format files under the configuration directory and send it to the remote
key-value storage.

Try running:
"

Command "handoff -p 03_exchange_rates config push"

echo '
Look at the end of the log that says,

```shell
    See the parameters at https://console.aws.amazon.com/systems-manager/parameters/?region=...
```

Grab the link and open in the browswer (AWS login required) to confirm that
the parameters are uploaded.
'

Prompt

echo "
We also have some files needed for the task execution:
"

ListDir "03_exchange_rates/files"

echo "
We need to store this somewhere accessible.
So we will create a cloud data storage (S3 bucket) for that.

Try running:
"

Command "handoff -p 03_exchange_rates cloud create_bucket"

echo '
Wait for a minute and check here

```shell
    https://s3.console.aws.amazon.com
```

to make sure the bucket is created before you proceed.
'

if [[ $MODE = "auto" ]]; then sleep 3m; fi

Prompt

echo "
Now it's time to push the files to the bucket.

Try running:
"

Command "handoff -p 03_exchange_rates files push"

echo '
Look at the end of the log that says,

```shell
    See the files at https://s3.console.aws.amazon.com/s3/...
```

Grab the link and open in the browswer (AWS login required) to see the files
directory is uploaded.
'

Prompt

echo "
Install the workspace:
"

Command "handoff -p 03_exchange_rates -w workspace workspace install"

echo "
Now let's run the command by pulling the configurations and files from remote. 

Try running:
"
Command "handoff -p 03_exchange_rates -w workspace run remote_config --push-artifacts"

echo '
Notice that we used --push-artifacts option in the last command.
With this option, we pushed the result to the bucket under


```shell'

TASK=`handoff -p 03_exchange_rates envs get -d '{"key":"HO_TASK"}' -l critical`

echo "    $TASK/last/artifacts"

echo '
```

directory.
'

echo '
Also note that artifacts are automatically archived at each run at

```shell
'

echo "
    $TASK/runs/
"

echo '
```

directory.
'

Prompt

Thanks

echo "
Next step is to prepare a Docker image and test running it locally.
"

Continue scripts/aws_get_started/05_docker
