Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8f16a38
feat: make lambda function command
wilsenhc Jul 7, 2023
5ca8547
Fix code styling [ci skip]
wilsenhc Jul 7, 2023
f3bc3de
feat: add command to service provider
wilsenhc Jul 10, 2023
73b3dc7
feat: update commad + move stubs
wilsenhc Jul 10, 2023
d5f19ee
Fix code styling [ci skip]
wilsenhc Jul 10, 2023
25a51e8
fix: fix stubs path
wilsenhc Jul 10, 2023
c8da115
docs: finish up documentation for make function command
wilsenhc Jul 30, 2023
71da487
fix: remove creates matching test
wilsenhc Jul 30, 2023
c2c8893
feat: update readme
wilsenhc Jul 31, 2023
80d4157
Merge branch 'feature/update-lambda-runtimes' into feature/make-funct…
wilsenhc Aug 3, 2023
960724b
Merge branch 'feature/update-lambda-runtimes' into feature/make-funct…
wilsenhc Nov 10, 2023
b2d6ab7
feat: make nodejs20.x the default runtime
wilsenhc Nov 10, 2023
d553e36
Merge branch 'feature/update-lambda-runtimes' into feature/make-funct…
wilsenhc Jan 10, 2024
76ad19d
Merge branch 'main' into feature/make-function-command
wilsenhc Jan 10, 2024
bfee5b2
fix: missing eol
wilsenhc Jan 10, 2024
8673f26
Merge branch 'hammerstonedev:main' into feature/make-function-command
wilsenhc Mar 21, 2024
7f50d04
Merge branch 'hammerstonedev:main' into feature/make-function-command
wilsenhc May 15, 2024
b051a5e
Merge branch 'hammerstonedev:main' into feature/make-function-command
wilsenhc May 15, 2024
e4180a6
Merge branch 'hammerstonedev:main' into feature/make-function-command
wilsenhc May 15, 2024
a65ec49
Merge branch 'aarondfrancis:main' into feature/make-function-command
wilsenhc Oct 27, 2025
7950d4a
Fix code styling [ci skip]
wilsenhc Oct 27, 2025
8eaf674
Initial plan
Copilot Oct 27, 2025
2f3cd4d
Fix getArguments method - rename to getOptions with correct runtime o…
Copilot Oct 27, 2025
6971c38
Add default value to runtime option in signature for consistency
Copilot Oct 27, 2025
5aeca7e
Merge pull request #1 from wilsenhc/copilot/fix-argument-declaration
wilsenhc Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ Every Sidecar Function requires two things:
- A PHP Class
- Files that you want deployed to Lambda

For example, if we were wanting to use Node on Lambda to generate an og:image for all of our blog posts, we would first set up a simple class in PHP called `OgImage`.
For example, if we were wanting to use Node on Lambda to generate an `og:image` for all of our blog posts, we would first set up a simple class in PHP called `OgImage`.
To do this we can run the command:

```bash
php artisan make:lambda-function OgImage
```


`App\Sidecar\OgImage.php`

Expand Down
21 changes: 18 additions & 3 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,33 @@ php artisan sidecar:install

## Configure

The configure command is an interactive command that walks you through setting up your AWS credentials. Dealing with AWS IAM can be a pain, so we wrote this command to do it for you.
The configure command is an interactive command that walks you through setting up your AWS credentials. Dealing with AWS IAM can be a pain, so we wrote this command to do it for you.

```text
php artisan sidecar:configure
```

## Make

The make command will create a new function class in your `app/Sidecar` directory.

```text
php artisan make:lambda-function MyFunction
```

You can also pass a `--runtime=` flag to specify the runtime you want to use. The default runtime for newly created functions is `nodejs20.x`.
To see a list of available runtimes, see the [Runtime](functions/customization#runtime) section.

```text
php artisan make:lambda-function MyFunction --runtime=python3.10
```

## Deploy

The deploy command deploys your functions to Lambda, and can optionally activate them.

To deploy but not activate, run the command without any arguments.
To deploy but not activate, run the command without any arguments.

```text
php artisan sidecar:deploy
```
Expand Down
99 changes: 99 additions & 0 deletions src/Commands/MakeLambdaFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

/**
* @author Wilsen Hernández <[email protected]|https://github.com/wilsenhc>
*/

namespace Hammerstone\Sidecar\Commands;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;

#[AsCommand(name: 'make:lambda-function')]
class MakeLambdaFunction extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:lambda-function {name} {--runtime= : The runtime that will be used to create the lambda function}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new Sidecar Lambda function class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Lambda';

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/lambda-function.stub');
}

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath($stub)
{
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
: __DIR__ . $stub;
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return "{$rootNamespace}\Sidecar";
}

/**
* Replace the class name for the given stub.
*
* @param string $stub
* @param string $name
* @return string
*/
protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);

$runtime = $this->option('runtime') ?: 'nodejs20.x';

return str_replace(['nodejs20.x', '{{ runtime }}'], $runtime, $stub);
}

/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the lambda function already exists'],
['runtime', null, InputOption::VALUE_OPTIONAL, 'The runtime that will be used to create the lambda function'],
];
}
}
1 change: 0 additions & 1 deletion src/Commands/Warm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Hammerstone\Sidecar\Commands;

use Hammerstone\Sidecar\Sidecar;
use Illuminate\Console\Command;

class Warm extends EnvironmentAwareCommand
{
Expand Down
31 changes: 31 additions & 0 deletions src/Commands/stubs/lambda-function.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace {{ namespace }};

use Hammerstone\Sidecar\LambdaFunction;

class {{ class }} extends LambdaFunction
{
/**
* The function within your code that Lambda calls to begin execution.
* @inheritDoc
*
* @return string
*/
public function handler()
{
return 'sidecar/function.handler';
}

/**
* The runtime environment for the Lambda function.
*
* @see https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
*
* @return string
*/
public function runtime()
{
return '{{ runtime }}';
}
}
2 changes: 2 additions & 0 deletions src/Providers/SidecarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Hammerstone\Sidecar\Commands\Configure;
use Hammerstone\Sidecar\Commands\Deploy;
use Hammerstone\Sidecar\Commands\Install;
use Hammerstone\Sidecar\Commands\MakeLambdaFunction;
use Hammerstone\Sidecar\Commands\Warm;
use Hammerstone\Sidecar\Contracts\AwsClientConfiguration as AwsClientConfigurationContract;
use Hammerstone\Sidecar\Manager;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function boot()
Warm::class,
Deploy::class,
Install::class,
MakeLambdaFunction::class,
]);
}

Expand Down