# EasySAM Examples Catalog

This folder contains focused examples of EasySAM features and AWS integration patterns.

## Common workflow

From repository root:

```bash
easysam --environment dev inspect schema example/<example-name>
easysam --environment dev generate example/<example-name>
easysam --environment dev deploy example/<example-name>
```

If EasySAM is installed project-locally with uv, replace `easysam` with `uv run easysam`.

## Example matrix

| Example | Focus | AWS services |
| --- | --- | --- |
| `myapp` | Minimal app with imported lambda + table | Lambda, API Gateway, DynamoDB |
| `onelambda` | Smallest lambda-only application | Lambda |
| `onelambda314` | Custom Python version and Lambda settings | Lambda |
| `appwitherrors` | Intentional schema errors for validation testing | Validation flow |
| `conditionals` | Conditional resources + context-file overrides | S3, Lambda, API Gateway, DynamoDB |
| `customlayer` | Per-function external Lambda layer via SSM reference | Lambda, SSM |
| `userenvvars` | Global function env vars from `resources.yaml` | Lambda |
| `plugins` | Template plugin rendering custom SAM fragments | Plugin system, Lambda |
| `dynamottl` | DynamoDB TTL in table definitions | DynamoDB |
| `prismarine` | Prismarine TypedDict tables + stream trigger lambda | DynamoDB, Lambda, Prismarine |
| `prismarinettl` | Prismarine model-level TTL (`ttl=...`) | DynamoDB, Prismarine |
| `prismapydantic` | Prismarine Pydantic modelling + CRUD integration test | DynamoDB, Prismarine, Pydantic |
| `functionurl` | Lambda Function URLs (simple + CORS) | Lambda |
| `aoss` | OpenSearch Serverless + DynamoDB Streams indexing | DynamoDB, Lambda, AOSS |
| `kinesismutltiplebuckets` | Kinesis stream delivery to multiple S3 destinations | Kinesis, Firehose, S3, Lambda |

## Example notes

### `myapp`

- Baseline project structure generated by `easysam init`.
- Includes local import (`backend/**/easysam.yaml`) and API integration path `/items`.

### `onelambda`

- Simplest lambda declaration (`lambda.name`) without additional resources.
- Good first smoke test for credentials and deployment pipeline.

### `onelambda314`

- Variation of `onelambda` that specifies `python: "3.14"`.
- Demonstrates custom `timeout` and `memory` overrides in the local `easysam.yaml`.

### `appwitherrors`

- Contains intentional invalid configuration (`backend/database/easysam.yaml`).
- Use it to validate error reporting:

```bash
easysam --environment dev inspect schema example/appwitherrors
```

### `conditionals`

- Demonstrates `!Conditional` with environment and region matching.
- Uses override file `deploy-context.yaml`:

```bash
easysam --environment prod --target-region eu-west-2 --context-file example/conditionals/deploy-context.yaml inspect schema example/conditionals
```

### `customlayer`

- Demonstrates attaching an external layer ARN via dynamic SSM parameter.
- Requires parameter `/ffmpeg-latest-arn` in the target account/region.

### `userenvvars`

- Adds global `envvars` in root `resources.yaml`.
- Test script prints `MY_ENV_VAR` returned by lambda.

### `plugins`

- Renders custom fragment from `customlambda.j2` into `myplugin.yaml`.
- Useful for edge resources not covered by built-in model.

### `dynamottl`

- Enables DynamoDB TTL via `ttl: ExpireAt` in table definition.
- No lambda required; pure table example.

### `prismarine`

- Uses Prismarine TypedDict models to define table shape.
- Configures stream trigger with `trigger='itemlogger'`.

### `prismarinettl`

- Prismarine table model includes `ttl='ExpireAt'`.
- Good reference for model-driven expiry configuration.

### `prismapydantic`

- Uses `prismarine.modelling: pydantic`.
- Includes integration test `tests/test_item_crud.py` (real AWS interaction).

### `functionurl`

- Demonstrates simple (`functionurl: true`) and advanced CORS configuration.
- Lambda outputs include the generated URL.

### `aoss`

- Defines DynamoDB table with trigger to `indexfunc`.
- `indexfunc` processes stream INSERT/MODIFY/REMOVE and updates AOSS index.
- `searchfunc` runs simple match-all query against the collection.

### `kinesismutltiplebuckets`

- Demonstrates stream delivery fan-out to:
  - internal bucket destination
  - conditional external bucket ARN destination via context override
- Override file: `deploy-context.yaml`.

## Cleanup

After trying an example:

```bash
easysam --environment dev delete --await
```

Use the same environment name you deployed with.
