Skip to content

Commit e29df01

Browse files
committed
Docs
1 parent a0506ec commit e29df01

File tree

7 files changed

+182
-31
lines changed

7 files changed

+182
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.claude/
12
/vendor
23
/storage/framework/testing
34
.env

CLAUDE.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## What is Sidecar?
6+
7+
Sidecar is a Laravel package that lets you deploy and run AWS Lambda functions directly from your Laravel app. Write a function in Node, Python, Ruby, Java, or any Lambda-supported runtime, and call it from PHP as easily as `MyFunction::execute(['key' => 'value'])`.
8+
9+
The package handles all the AWS complexity: packaging your code, uploading to S3, creating/updating Lambda functions, managing versions, and invoking them.
10+
11+
## Testing
12+
13+
```bash
14+
# Run all tests
15+
./vendor/bin/phpunit
16+
17+
# Run a single test file
18+
./vendor/bin/phpunit tests/Unit/FunctionTest.php
19+
20+
# Run a specific test method
21+
./vendor/bin/phpunit --filter test_runtime_value_resolves_enum_to_string
22+
```
23+
24+
Tests use Orchestra Testbench. The test suite has unit tests in `tests/Unit/` and integration tests in `tests/Integration/`. Most development work uses unit tests with mocked AWS clients.
25+
26+
## How the Code is Organized
27+
28+
### The Main Players
29+
30+
**`LambdaFunction`** is the abstract base class that users extend. Every function needs two methods:
31+
- `handler()` - tells Lambda which file/function to run (e.g., `'image.handler'`)
32+
- `package()` - lists files to include in the deployment ZIP
33+
34+
Users call static methods like `MyFunction::execute($payload)` to run their functions.
35+
36+
**`Manager`** (accessed via the `Sidecar` facade) does the actual work of invoking Lambda functions. It prepares payloads, calls the AWS SDK, and wraps responses in result objects.
37+
38+
**`Deployment`** handles the deploy workflow: package the code, create or update the Lambda function, then optionally activate it by pointing an alias to the new version.
39+
40+
**`Package`** builds the ZIP file for deployment. It collects files based on include/exclude patterns, computes a hash for change detection, and streams the ZIP directly to S3.
41+
42+
### AWS Clients
43+
44+
The `src/Clients/` directory has thin wrappers around AWS SDK clients:
45+
- `LambdaClient` extends the SDK client and adds retry logic for Lambda's "Pending" state
46+
- `S3Client` and `CloudWatchLogsClient` are simpler wrappers
47+
48+
### Results
49+
50+
When you execute a function:
51+
- Sync calls return a `SettledResult` with the response body, logs, and error info
52+
- Async calls return a `PendingResult` that resolves to `SettledResult` when you call `->settled()`
53+
54+
### Runtime and Architecture
55+
56+
`Runtime` and `Architecture` are PHP 8.1 backed enums. There are also deprecated `RuntimeConstants` and `ArchitectureConstants` classes for backwards compatibility.
57+
58+
When working with these, use `runtimeValue()` and `architectureValue()` methods to get the string values - they handle both enum and string inputs.
59+
60+
## Configuration
61+
62+
Everything lives in `config/sidecar.php`:
63+
- `functions` - array of `LambdaFunction` classes to deploy
64+
- `env` - environment name, used to namespace function names (defaults to `APP_ENV`)
65+
- `timeout`, `memory`, `storage` - default Lambda settings
66+
- AWS credentials (`aws_key`, `aws_secret`, `aws_region`, `aws_bucket`, `execution_role`)
67+
68+
Function names are automatically prefixed with app name and environment to avoid collisions.
69+
70+
## Artisan Commands
71+
72+
These are what users run (not needed for package development, but good to know):
73+
- `sidecar:deploy` - packages and deploys functions to Lambda
74+
- `sidecar:activate` - points the "active" alias to latest version
75+
- `sidecar:deploy --activate` - both in one step
76+
- `sidecar:warm` - pre-warms function instances to reduce cold starts
77+
- `sidecar:configure` - interactive wizard to set up AWS resources
78+
79+
## Events
80+
81+
The package fires Laravel events you can hook into:
82+
- `BeforeFunctionsDeployed` / `AfterFunctionsDeployed`
83+
- `BeforeFunctionsActivated` / `AfterFunctionsActivated`
84+
- `BeforeFunctionExecuted` / `AfterFunctionExecuted`
85+
86+
## Things to Know
87+
88+
- This package supports Laravel 8 through 12 and PHP 8.1+
89+
- All source files use `declare(strict_types=1)`
90+
- The codebase uses constructor property promotion and typed properties throughout
91+
- Tests use Mockery for mocking AWS clients - check existing tests for patterns

docs/events.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11

22
# Events
33

4-
Sidecar fires a few events related to deployment that you can hook into:
4+
Sidecar fires events during deployment, activation, and execution that you can hook into.
5+
6+
## Deployment & Activation Events
57

68
- `BeforeFunctionsDeployed`
79
- `AfterFunctionsDeployed`
810
- `BeforeFunctionsActivated`
911
- `AfterFunctionsActivated`
1012

11-
Each of these events has a public `functions` property that holds all the functions that are being deployed or activated.
13+
Each of these events has a public `functions` property that holds all the functions being deployed or activated. You can use these to build packages, install dependencies, or clean up after deployment.
14+
15+
## Execution Events
16+
17+
- `BeforeFunctionExecuted`
18+
- `AfterFunctionExecuted`
19+
20+
These events fire every time a function is executed. `BeforeFunctionExecuted` has `function` and `payload` properties. `AfterFunctionExecuted` adds the `result` property.
1221

13-
You can use these events to build packages, install dependencies, or clean up after they are deployed.
22+
You can use these for logging, monitoring, or modifying payloads before they're sent to Lambda.

docs/functions/customization.md

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,52 @@ The only two things _required_ for a Sidecar function are the [package and the h
55

66
## Runtime
77

8-
Lambda supports multiple languages through the use of runtimes. You can choose any of the following runtimes by returning its corresponding identifier:
9-
10-
- Node.js 20: `nodejs20.x`
11-
- Node.js 18: `nodejs18.x`
12-
- Python 3.12: `python3.12`
13-
- Python 3.11: `python3.11`
14-
- Python 3.10: `python3.10`
15-
- Python 3.9: `python3.9`
16-
- Java 21: `java21`
17-
- Java 17: `java17`
18-
- Java 11: `java11`
19-
- Java 8: `java8.al2`
20-
- .NET 8: `dotnet8`
21-
- .NET 6: `dotnet6`
22-
- Ruby 3.3: `ruby3.3`
23-
- Ruby 3.2: `ruby3.2`
24-
- OS-only runtime (Amazon Linux 2023): `provided.al2023`
25-
- OS-only runtime (Amazon Linux 2): `provided.al2`
26-
27-
E.g. to use the Python 3.12 runtime, you would return `python3.12`:
8+
Lambda supports multiple languages through the use of runtimes. Sidecar provides a `Runtime` enum with all supported runtimes, or you can return the runtime identifier as a string.
9+
10+
Available runtimes include:
11+
12+
- Node.js 24: `Runtime::NODEJS_24` or `'nodejs24.x'`
13+
- Node.js 22: `Runtime::NODEJS_22` or `'nodejs22.x'`
14+
- Node.js 20: `Runtime::NODEJS_20` or `'nodejs20.x'`
15+
- Python 3.14: `Runtime::PYTHON_314` or `'python3.14'`
16+
- Python 3.13: `Runtime::PYTHON_313` or `'python3.13'`
17+
- Python 3.12: `Runtime::PYTHON_312` or `'python3.12'`
18+
- Python 3.11: `Runtime::PYTHON_311` or `'python3.11'`
19+
- Python 3.10: `Runtime::PYTHON_310` or `'python3.10'`
20+
- Python 3.9: `Runtime::PYTHON_39` or `'python3.9'`
21+
- Java 25: `Runtime::JAVA_25` or `'java25'`
22+
- Java 21: `Runtime::JAVA_21` or `'java21'`
23+
- Java 17: `Runtime::JAVA_17` or `'java17'`
24+
- Java 11: `Runtime::JAVA_11` or `'java11'`
25+
- Java 8: `Runtime::JAVA_8_LINUX2` or `'java8.al2'`
26+
- .NET 9: `Runtime::DOT_NET_9` or `'dotnet9'`
27+
- .NET 8: `Runtime::DOT_NET_8` or `'dotnet8'`
28+
- Ruby 3.4: `Runtime::RUBY_34` or `'ruby3.4'`
29+
- Ruby 3.3: `Runtime::RUBY_33` or `'ruby3.3'`
30+
- Ruby 3.2: `Runtime::RUBY_32` or `'ruby3.2'`
31+
- OS-only runtime (Amazon Linux 2023): `Runtime::PROVIDED_AL2023` or `'provided.al2023'`
32+
- OS-only runtime (Amazon Linux 2): `Runtime::PROVIDED_AL2` or `'provided.al2'`
33+
34+
You can use either the enum or a string:
2835

2936
```php
37+
use Hammerstone\Sidecar\Runtime;
38+
3039
class ExampleFunction extends LambdaFunction
3140
{
3241
public function runtime() // [tl! focus:3]
3342
{
43+
// Using the enum (recommended)
44+
return Runtime::PYTHON_312;
45+
46+
// Or using a string
3447
return 'python3.12';
3548
}
3649
}
3750
```
3851

52+
The default runtime is `Runtime::NODEJS_20`.
53+
3954
Read more in the [AWS Documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
4055

4156
## Memory

docs/functions/deploying.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ When you run that, you'll see an output log similar to the one below:
1414
```text
1515
[Sidecar] Deploying App\Sidecar\OgImage to Lambda as `SC-Laravel-local-Sidecar-OgImage`.
1616
↳ Environment: local
17-
↳ Runtime: nodejs12.x
17+
↳ Runtime: nodejs20.x
1818
↳ Packaging function code.
1919
↳ Creating a new zip file.
2020
↳ Zip file created at s3://sidecar-us-east-2-XXX/sidecar/001-79a5915eaec296be04a0f4fb7cc80e40.zip

docs/functions/performance.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11

2-
# Performance
2+
# Performance Tips
3+
4+
Here are some tips for getting the best performance out of your Sidecar functions.
5+
6+
## Reduce Cold Starts
7+
8+
Cold starts happen when Lambda spins up a new container to handle your request. To minimize their impact:
9+
10+
- **Use warming** - Configure `warmingConfig()` on your functions and schedule `sidecar:warm` to run regularly. See [Warming Functions](warming) for details.
11+
- **Use pre-warming** - Add `--pre-warm` when activating to warm functions before they go live.
12+
- **Keep functions warm** - Schedule `sidecar:warm` to run every 5 minutes to prevent containers from being frozen.
13+
14+
## Optimize Your Package Size
15+
16+
Smaller packages deploy faster and have quicker cold starts:
17+
18+
- **Separate your node_modules** - Keep Lambda dependencies in a separate `package.json` from your main app.
19+
- **Use NCC** - Compile Node.js handlers into a single file with [NCC](https://github.com/vercel/ncc). See [Handlers & Packages](handlers-and-packages#compiling-your-handler-with-ncc).
20+
- **Only include what you need** - Be specific about what goes in your `package()` method.
21+
22+
## Right-Size Memory
23+
24+
Lambda allocates CPU proportionally to memory. More memory means more CPU:
25+
26+
- **Profile your functions** - Use `$result->report()` to see memory usage and execution time.
27+
- **Test different memory settings** - Sometimes paying for more memory results in faster execution and lower total cost.
28+
29+
## Use Async When Possible
30+
31+
If you don't need the result immediately:
32+
33+
- **Use `executeAsync()`** - Let your code continue while Lambda runs in the background.
34+
- **Use `executeMany()`** - Run multiple invocations in parallel instead of sequentially.
35+
- **Use `executeAsEvent()`** - For fire-and-forget scenarios where you don't need the response.
336

docs/overview.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@
33

44
Sidecar packages, deploys, and executes AWS Lambda functions from your Laravel application. {.text-xl .font-bold}
55

6-
It works with _any_ Laravel 7, 8, 9 or 10 application, hosted _anywhere_, including your local machine. {.font-bold}
6+
It works with _any_ Laravel 8, 9, 10, 11, or 12 application, hosted _anywhere_, including your local machine. {.font-bold}
77

88
You can write functions in any of the following runtimes and execute them straight from PHP:
99

10+
- Node.js 24
11+
- Node.js 22
1012
- Node.js 20
11-
- Node.js 18
12-
- Node.js 16
13+
- Python 3.14
14+
- Python 3.13
1315
- Python 3.12
1416
- Python 3.11
1517
- Python 3.10
1618
- Python 3.9
17-
- Python 3.8
19+
- Java 25
1820
- Java 21
1921
- Java 17
2022
- Java 11
2123
- Java 8
24+
- .NET 9
2225
- .NET 8
23-
- .NET 7
24-
- .NET 6
26+
- Ruby 3.4
2527
- Ruby 3.3
2628
- Ruby 3.2
2729
- OS-only runtime (Amazon Linux 2023)

0 commit comments

Comments
 (0)