
---

## 🚀 Setup Instructions for Flink with Python 3.11.9

Follow these steps to set up your environment using `pyenv` and install `apache-flink`.

### 1. Open Terminal and Navigate to Project Directory

```bash
cd path/to/flink-app
```

> Replace `path/to/flink-app` with the actual path to your `flink-app` folder.

---

### 2. Install Java 17 (Required for Flink)

```bash
brew install openjdk@17
```

### 3. Install `pyenv` (if not already installed)

```bash
brew install pyenv
brew install pyenv-virtualenv
```

### 4. Configure Shell Environment

Add Java and pyenv to your shell configuration:

```bash
echo 'export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc
echo 'export JAVA_HOME="/opt/homebrew/opt/openjdk@17"' >> ~/.zshrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
source ~/.zshrc
```

> **Note:** If you use a different shell (like bash), replace `~/.zshrc` with `~/.bashrc` or `~/.bash_profile`.

---

### 5. Install Python 3.11.9

```bash
pyenv install 3.11.9
```

---

### 6. Set Python 3.11.9 Locally

```bash
pyenv local 3.11.9
```

---

### 7. Create and Activate a Virtual Environment

```bash
pyenv virtualenv 3.11.9 newenv
pyenv activate newenv
```

> **Troubleshooting:** If activation fails, try manually activating with:
> ```bash
> source ~/.pyenv/versions/newenv/bin/activate
> ```

---

### 8. Install Python Dependencies

```bash
pip install apache-flink
```

---

### 9. Configure AWS Credentials (If you encounter credential issues)

If you see AWS credential errors when running Flink applications, choose one of the following methods:

#### Method 1: Create a staging AWS profile
```bash
aws configure --profile staging
```

When prompted, enter:
- AWS Access Key ID: [your-access-key]
- AWS Secret Access Key: [your-secret-key]
- Default region name: us-east-2
- Default output format: json

Then set the profile for your session:
```bash
export AWS_PROFILE=staging
```

#### Method 2: Use AWS Access Portal (Recommended for SSO users)
1. Go to AWS Access Portal (typically https://sunoai.awsapps.com/start)
2. Find the **suno-staging** account
3. Click on the **Administrator** role
4. Click **"Access keys"** next to the role
5. Copy the AWS environment variables
6. Paste them into your terminal:
```bash
export AWS_ACCESS_KEY_ID=ASIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_SESSION_TOKEN=...
```

#### Verify the configuration:
```bash
aws configure list
```

You should see credentials are loaded and active.

---

### 10. Run a flink file
``` bash 
python app-user-like-history/main.py
```

> **Note:** Make sure you have set the AWS_PROFILE environment variable to `staging` before running the Flink application if you encounter credential issues.