Sidecar — Deploy and execute AWS Lambda functions from your Laravel application.

Configuring Sidecar

Configuring AWS

Sidecar requires a few very specific things be set up in your AWS in order to have the proper permissions to deploy and execute your functions.

In order to save you from the frustration of AWS IAM, we have written a single, interactive command that can handle everything for you.

To get started, run the following command:

1php artisan sidecar:configure

The first thing it will do is guide you through creating a new AWS user, which it will then use to create everything else it needs.

Note that this won't start any services, it just creates some policies in IAM.

This is the same method that Vapor uses: you provide it with Admin Access and then it configures itself.

If you'd like to manually set everything up, take a look at the command to see exactly what it's doing, and you can recreate it in the IAM portal.

Registering Functions

Each function that you make will need to be registered in the functions key of your sidecar.php

sidecar.php

1return [
2 /*
3 * All of your function classes that you'd like to deploy go here.
4 */
5 'functions' => [
6 \App\Sidecar\OgImage::class,
7 \App\Sidecar\ProcessThumbnail::class,
8 ],
9
10 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11 * *
12 * You are welcome to edit this configuration directly, or you can run *
13 * `php artisan sidecar:configure` for an interactive walk-through. *
14 * *
15 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16
17 /*
18 * Your AWS key. See CreateDeploymentUser::policy for the IAM policy.
19 *
20 * Unfortunately you cannot rely on the keys available in the Vapor
21 * runtime, as those do not have the right permissions.
22 */
23 'aws_key' => env('SIDECAR_ACCESS_KEY_ID'),
24
25 /*
26 * Your AWS secret key.
27 */
28 'aws_secret' => env('SIDECAR_SECRET_ACCESS_KEY'),
29
30 /*
31 * The region where your Lambdas will be deployed.
32 */
33 'aws_region' => env('SIDECAR_REGION'),
34
35 /*
36 * The bucket that temporarily holds your function's ZIP files as they
37 * are deployed to Lambda. It must be the same region as your Lambdas.
38 */
39 'aws_bucket' => env('SIDECAR_ARTIFACT_BUCKET_NAME'),
40
41 /*
42 * This is the execution role that your Lambdas will use.
43 *
44 * See CreateExecutionRole::policy for the IAM policy.
45 */
46 'execution_role' => env('SIDECAR_EXECUTION_ROLE'),
47
48 /*
49 * The default timeout for your functions, in seconds.
50 * This can be overridden per function.
51 */
52 'timeout' => env('SIDECAR_TIMEOUT', 300),
53
54 /*
55 * The default memory for your functions, in megabytes.
56 * This can be overridden per function.
57 */
58 'memory' => env('SIDECAR_MEMORY', 512),
59
60 /*
61 * The base path for your package files. If you e.g. keep
62 * all your Lambda package files in your resource path,
63 * you may change the base path here.
64 */
65 'package_base_path' => env('SIDECAR_PACKAGE_BASE_PATH', base_path()),
66];

Default Settings

The timeout and memory can be customized on a per-function basis, but if they aren't, the defaults from your sidecar.php file will be used.

Package Base Path

By default, all of your Lambda resources are going to be relative to the base_path() of your application. That means when you're defining your code packages, you'll use the root of your application as the starting point.

If all of your Lambda code lives in e.g. resources/lambda, then you can update your package_base_path to reflect that.

sidecar.php

1return [
2
3 /*
4 * All of your function classes that you'd like to deploy go here.
5 */
6 'functions' => [
7 \App\Sidecar\OgImage::class,
8 \App\Sidecar\ProcessThumbnail::class,
9 ],
10
11 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
12 * *
13 * You are welcome to edit this configuration directly, or you can run *
14 * `php artisan sidecar:configure` for an interactive walk-through. *
15 * *
16 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
17
18 /*
19 * Your AWS key. See CreateDeploymentUser::policy for the IAM policy.
20 *
21 * Unfortunately you cannot rely on the keys available in the Vapor
22 * runtime, as those do not have the right permissions.
23 */
24 'aws_key' => env('SIDECAR_ACCESS_KEY_ID'),
25
26 /*
27 * Your AWS secret key.
28 */
29 'aws_secret' => env('SIDECAR_SECRET_ACCESS_KEY'),
30
31 /*
32 * The region where your Lambdas will be deployed.
33 */
34 'aws_region' => env('SIDECAR_REGION'),
35
36 /*
37 * The bucket that temporarily holds your function's ZIP files as they
38 * are deployed to Lambda. It must be the same region as your Lambdas.
39 */
40 'aws_bucket' => env('SIDECAR_ARTIFACT_BUCKET_NAME'),
41
42 /*
43 * This is the execution role that your Lambdas will use.
44 *
45 * See CreateExecutionRole::policy for the IAM policy.
46 */
47 'execution_role' => env('SIDECAR_EXECUTION_ROLE'),
48
49 /*
50 * The default timeout for your functions, in seconds.
51 * This can be overridden per function.
52 */
53 'timeout' => env('SIDECAR_TIMEOUT', 300),
54
55 /*
56 * The default memory for your functions, in megabytes.
57 * This can be overridden per function.
58 */
59 'memory' => env('SIDECAR_MEMORY', 512),
60
61 /*
62 * The base path for your package files. If you e.g. keep
63 * all your Lambda package files in your resource path,
64 * you may change the base path here.
65 */
66 'package_base_path' => env('SIDECAR_PACKAGE_BASE_PATH', base_path()),
67];