|
| 1 | +# AWS-S3 DataConnector Scripts Bundle Automation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The AWS-S3 DataConnector scripts are automatically bundled into zip files whenever changes are made to the source files. This automation ensures that the distributed zip files are always up-to-date with the latest script changes. |
| 6 | + |
| 7 | +## Automated Bundles |
| 8 | + |
| 9 | +Two main zip files are automatically maintained: |
| 10 | + |
| 11 | +1. **ConfigAwsS3DataConnectorScripts.zip** - For Commercial Azure |
| 12 | + - Contains: `ConfigAwsComToAzureCom.zip` and `ConfigAwsGovToAzureCom.zip` |
| 13 | + - Includes both `CloudWatchLambdaFunction.py` and `CloudWatchLambdaFunction_V2.py` |
| 14 | + |
| 15 | +2. **ConfigAwsS3DataConnectorScriptsGov.zip** - For Government Azure |
| 16 | + - Contains: `ConfigAwsComToAzureGov.zip` and `ConfigAwsGovToAzureGov.zip` |
| 17 | + - Includes only `CloudWatchLambdaFunction.py` (V1) |
| 18 | + |
| 19 | +## How It Works |
| 20 | + |
| 21 | +### GitHub Actions Workflow |
| 22 | + |
| 23 | +The automation is implemented via a GitHub Actions workflow (`.github/workflows/aws-s3-bundle-update.yaml`) that: |
| 24 | + |
| 25 | +1. **Triggers automatically** on: |
| 26 | + - **Pull Requests** targeting the `master` branch |
| 27 | + - When changes affect: |
| 28 | + - `*.ps1` files in the AWS-S3 directory |
| 29 | + - `*.py` files in the AWS-S3 directory |
| 30 | + - `*.md` files in the AWS-S3 directory |
| 31 | + - Files in `CloudFormation/`, `Enviornment/`, or `Utils/` subdirectories |
| 32 | + |
| 33 | +2. **Auto-Update Mode**: |
| 34 | + - Runs the bundling script to regenerate zip files |
| 35 | + - Automatically commits updated bundles to the PR branch |
| 36 | + - Includes `[skip ci]` flag to prevent workflow recursion |
| 37 | + - Developers don't need to manually update bundles - it's handled automatically |
| 38 | + - Commits are made by GitHub Action bot with clear description |
| 39 | + |
| 40 | +3. **Prevents recursion** by: |
| 41 | + - Excluding zip file changes from triggering the workflow |
| 42 | + - Checking if the commit already contains zip updates |
| 43 | + - Using `[skip ci]` flag in auto-commit messages |
| 44 | + |
| 45 | +### Bundling Script |
| 46 | + |
| 47 | +The `.script/bundleAwsS3Scripts.sh` script uses intelligent, dynamic bundling: |
| 48 | + |
| 49 | +- **Dynamic File Detection**: Automatically detects changed files using `git diff` |
| 50 | + - Respects `GITHUB_BASE_REF` in CI/CD environments |
| 51 | + - Falls back to `HEAD~1` for local execution |
| 52 | + - Filters out `.zip` files and documentation automatically |
| 53 | +- **Intelligent Updates**: Extracts existing zip files and only replaces modified files |
| 54 | + - Uses `cmp -s` to compare file contents |
| 55 | + - Preserves unchanged files to minimize bundle changes |
| 56 | +- **Variant Handling**: Automatically manages differences between Commercial and Government bundles |
| 57 | + - Commercial: Includes both Lambda V1 and V2 |
| 58 | + - Government: Includes only Lambda V1 |
| 59 | +- **Nested Structure**: Creates proper nested zip file structure |
| 60 | +- **Fallback Safety**: If no changes detected, bundles all relevant files to ensure completeness |
| 61 | + |
| 62 | +## Files Included in Bundles |
| 63 | + |
| 64 | +The bundling script uses **dynamic file detection** to automatically determine which files to include: |
| 65 | + |
| 66 | +### Dynamic Detection Process |
| 67 | + |
| 68 | +1. **Changed Files Detection**: The script uses `git diff` to detect files that have been modified in the AWS-S3 directory |
| 69 | +2. **Automatic Filtering**: Excludes `.zip` files and `BUNDLE_AUTOMATION.md` from the bundle |
| 70 | +3. **Fallback Mechanism**: If no changes are detected, all relevant files in the AWS-S3 directory are bundled |
| 71 | + |
| 72 | +### File Types Included |
| 73 | + |
| 74 | +The script automatically bundles: |
| 75 | +- **PowerShell scripts** (`*.ps1`) - Configuration and connector scripts |
| 76 | +- **Python files** (`*.py`) - Lambda functions |
| 77 | +- **Markdown documentation** (`*.md`) - Policy and usage documentation |
| 78 | +- **CloudFormation templates** - Infrastructure-as-code definitions |
| 79 | +- **Utility scripts** - Helper functions and shared code in `Utils/` directory |
| 80 | +- **Environment configuration** - Settings in `Enviornment/` directory |
| 81 | + |
| 82 | +### Bundle Variants |
| 83 | + |
| 84 | +**Commercial Azure Bundles** (`ConfigAwsS3DataConnectorScripts.zip`): |
| 85 | +- Include both `CloudWatchLambdaFunction.py` and `CloudWatchLambdaFunction_V2.py` |
| 86 | +- Contain two nested zips: `ConfigAwsComToAzureCom.zip` and `ConfigAwsGovToAzureCom.zip` |
| 87 | + |
| 88 | +**Government Azure Bundles** (`ConfigAwsS3DataConnectorScriptsGov.zip`): |
| 89 | +- Include only `CloudWatchLambdaFunction.py` (V1) |
| 90 | +- Contain two nested zips: `ConfigAwsComToAzureGov.zip` and `ConfigAwsGovToAzureGov.zip` |
| 91 | + |
| 92 | +### Adding New Files |
| 93 | + |
| 94 | +Simply add or modify files in the `DataConnectors/AWS-S3/` directory. The bundling script will automatically detect and include them - no manual configuration needed! |
| 95 | + |
| 96 | +## Manual Bundle Generation |
| 97 | + |
| 98 | +If needed, you can manually regenerate the bundles: |
| 99 | + |
| 100 | +```bash |
| 101 | +# From the repository root |
| 102 | +.script/bundleAwsS3Scripts.sh |
| 103 | +``` |
| 104 | + |
| 105 | +Or trigger the workflow manually: |
| 106 | + |
| 107 | +1. Go to the Actions tab in the GitHub repository |
| 108 | +2. Select "AWS-S3 DataConnector Bundle Auto-Update" workflow |
| 109 | +3. Click "Run workflow" |
| 110 | +4. Select the branch and click "Run workflow" |
| 111 | + |
| 112 | +## Troubleshooting |
| 113 | + |
| 114 | +### Bundles not auto-updated in PR |
| 115 | + |
| 116 | +If bundles aren't automatically updated: |
| 117 | + |
| 118 | +1. Check the GitHub Actions tab to see if the workflow ran |
| 119 | +2. Verify your changes are in monitored paths (*.ps1, *.py, *.md, CloudFormation/, Enviornment/, Utils/) |
| 120 | +3. If workflow succeeded but no commit appeared, bundles may already be up-to-date |
| 121 | +4. Manually trigger the workflow from the Actions tab if needed |
| 122 | + |
| 123 | +### Manual bundle update needed |
| 124 | + |
| 125 | +If you prefer to update bundles manually or workflow fails: |
| 126 | + |
| 127 | +1. Run the bundling script locally: |
| 128 | + ```bash |
| 129 | + .script/bundleAwsS3Scripts.sh |
| 130 | + ``` |
| 131 | +2. Commit the updated zip files: |
| 132 | + ```bash |
| 133 | + git add DataConnectors/AWS-S3/*.zip |
| 134 | + git commit -m "Update AWS-S3 bundles" |
| 135 | + git push |
| 136 | + ``` |
| 137 | + |
| 138 | +### Workflow doesn't trigger |
| 139 | + |
| 140 | +- Ensure changes are in the monitored paths (see above) |
| 141 | +- Check that the PR targets the `master` branch |
| 142 | +- Verify the workflow file exists and is valid YAML |
| 143 | +- Check that zip files weren't the only changes (they're excluded from triggers) |
| 144 | + |
| 145 | +### Recursion issues |
| 146 | + |
| 147 | +If the workflow triggers itself repeatedly: |
| 148 | + |
| 149 | +- Check that the commit message includes `[skip ci]` |
| 150 | +- Verify the workflow doesn't trigger on zip file changes |
| 151 | +- Review the `check_changes` step logic in the workflow |
| 152 | + |
| 153 | +## Development Notes |
| 154 | + |
| 155 | +### Adding New Files to Bundles |
| 156 | + |
| 157 | +**No configuration needed!** The bundling script uses dynamic file detection: |
| 158 | + |
| 159 | +1. Simply add or modify files in the `DataConnectors/AWS-S3/` directory |
| 160 | +2. The script automatically detects changes via `git diff` |
| 161 | +3. New files are automatically included in the next bundle generation |
| 162 | + |
| 163 | +The script intelligently handles: |
| 164 | +- New PowerShell scripts (`*.ps1`) |
| 165 | +- New Python files (`*.py`) |
| 166 | +- New documentation (`*.md`) |
| 167 | +- New files in `CloudFormation/`, `Enviornment/`, or `Utils/` subdirectories |
| 168 | + |
| 169 | +### Modifying Bundle Structure |
| 170 | + |
| 171 | +To change which files go in which bundle variant (Commercial vs. Government): |
| 172 | + |
| 173 | +1. Edit the `create_nested_zip` function in `.script/bundleAwsS3Scripts.sh` |
| 174 | +2. Adjust the logic for the `lambda_version` parameter |
| 175 | +3. Test locally: `.script/bundleAwsS3Scripts.sh` |
| 176 | +4. Commit your changes |
| 177 | + |
| 178 | +### Understanding Dynamic Detection |
| 179 | + |
| 180 | +The script's `get_changed_files()` function: |
| 181 | +- Compares current branch against base branch (in PRs) or last commit (locally) |
| 182 | +- Automatically filters out `.zip` files and `BUNDLE_AUTOMATION.md` |
| 183 | +- Falls back to including all files if no changes are detected |
| 184 | +- Works seamlessly in both CI/CD and local development environments |
| 185 | + |
| 186 | +## Benefits |
| 187 | + |
| 188 | +✅ **Consistency**: Bundles are always in sync with source files |
| 189 | +✅ **Automation**: No manual zip file creation needed |
| 190 | +✅ **Transparency**: All changes are tracked in Git |
| 191 | +✅ **Reliability**: Automated testing ensures bundles are created correctly |
| 192 | +✅ **Documentation**: Clear process for maintenance and updates |
0 commit comments