# **_`sam build` in CI pipeline must not run with `--use-container`, and must use the default `.aws-sam` build directory (`--template-file` must not set)_**

## Development

1. Start local TiDB cluster

   ```bash
   # In another terminal, run:
   tiup playground
   ```

   > Note: A secret, whose content is the empty root paasword of playground TiDB, is already created manually in AWS
   Secrets Manager. The secret name is (
   unstable-plan-local-test-empty-passwd)[https://us-west-2.console.aws.amazon.com/secretsmanager/secret?name=unstable-plan-local-test-empty-passwd&region=us-west-2].

2. Import dummy data to TiDB

   ```bash
   mysql --comments --host 127.0.0.1 --port 4000 -u root -p -D test < ./example_data.sql > /dev/null
   ```

3. Build go binary

   ```bash
   # linux/amd64 and cgo-disabled is required by lambda runtime. 
   GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o handler
   ```

4. Build sam app

   ```bash
   sam build
   ```

5. Run sam app locally
    
   > Make sure that docker is running in the background.
   
   ```bash
   # Replace your AWS profile of the autonomous dev account in the following commands.
   AWS_PROFILE=auto-dev-rw sam local invoke -e ./example_event.json
   ```

6. (Optional) Test deploy

   > Make sure your aws profile is logged in and has the right permission.

   ```bash
    AWS_PROFILE=auto-dev-rw sam deploy \
            --stack-name "yifan-local-test-unstable-plan" \
            --region "us-west-2" \
            --s3-bucket "compute-engine-cd-staging" \
            --s3-prefix "yifan-local-test-unstable-plan" \
            --capabilities "CAPABILITY_IAM" \
            --no-confirm-changeset \
            --no-fail-on-empty-changeset \
            --parameter-overrides "Stage=staging"
    ```
