npm package: @firestone-hs/aws-lambda-utils
Description: npm run publish-version
Latest version: 1.1.1

# AWS Lambda Utils

npm run publish-version

rm -rf dist && tsc && rm -rf dist/node_modules && 'cp' -rf dist/ /e/Source/zerotoheroes/public-lambdas/cron-build-bgs-hero-stats/node_modules/@firestone-hs/aws-lambda-utils

## S3 Cost Monitoring

This repository now includes tools to monitor S3 costs by Lambda function origin. This helps you identify which Lambda functions are driving your S3 request costs.

### Quick Start

1. **Test Your Environment** (Recommended first step):

    ```bash
    ./test-aws-cli-paths.sh
    ```

2. **Simple Setup** (Recommended if encountering IAM issues):

    ```bash
    ./setup-s3-monitoring-simple.sh
    ```

    _Skips CloudWatch integration to avoid IAM role complexity_

3. **Full Automated Setup** (with CloudWatch integration):

    ```bash
    ./setup-s3-monitoring.sh
    ```

4. **If you encounter issues** (Windows Git Bash path problems):

    ```bash
    # Clean up existing resources and start fresh
    ./setup-s3-monitoring.sh --cleanup
    ```

5. **Manual Setup** (Windows PowerShell):
   Follow the guide in `MANUAL_SETUP_WINDOWS.md`

### What Gets Set Up

-   ✅ **CloudTrail** with S3 data events for your buckets (`xml.firestoneapp.com`, `static.zerotoheroes.com`)
-   ✅ **CloudWatch Log Group** for CloudTrail integration
-   ✅ **IAM Roles** for CloudTrail → CloudWatch permissions
-   ✅ **Sample CloudWatch Insights queries** to analyze S3 usage by Lambda function

### After Setup (15-30 minutes later)

Navigate to **CloudWatch → Insights** and run queries like:

```cloudwatch-insights
fields @timestamp, userIdentity.invokedBy, eventName, resources.0.ARN
| filter eventName like /GetObject/
| filter userIdentity.type = "AssumedRole"
| filter userIdentity.invokedBy like /lambda/
| stats count() as request_count by userIdentity.invokedBy
| sort request_count desc
```

### Expected Results

```
userIdentity.invokedBy                           | request_count
lambda.amazonaws.com:my-data-processor-function  | 15,247
lambda.amazonaws.com:my-backup-function          | 8,932
lambda.amazonaws.com:my-analytics-function       | 3,421
```

### Files

-   `setup-s3-monitoring-simple.sh` - Simple setup (no CloudWatch integration)
-   `setup-s3-monitoring.sh` - Full automated setup script
-   `test-aws-cli-paths.sh` - Environment compatibility test
-   `event-selectors.json` - S3 buckets to monitor
-   `s3-monitoring-queries.md` - Comprehensive monitoring guide
-   `MANUAL_SETUP_WINDOWS.md` - Windows PowerShell setup guide

### Cost Impact

-   **Setup time**: ~10 minutes
-   **Monthly cost**: ~\$2-5 (depends on request volume)
-   **Data availability**: 15-30 minutes after setup

### Troubleshooting

-   **Trail already exists**: Use `./setup-s3-monitoring.sh --cleanup`
-   **IAM role errors**: Use the simple version `./setup-s3-monitoring-simple.sh`
-   **Windows path issues**: Use `MANUAL_SETUP_WINDOWS.md` guide
-   **No data showing**: Wait 30 minutes for CloudTrail to populate

### Help

```bash
./setup-s3-monitoring.sh --help
```

---

## Original Package Info

This package provides utility classes for AWS Lambda functions including S3, RDS, SNS, SQS, and logging services.