Skip to content

Commit ce8b511

Browse files
committed
Docs [ci skip]
1 parent 19337df commit ce8b511

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
## Unreleased
33

4+
## 0.3.0 - 2021-07-20
5+
6+
### Added
7+
8+
- Support for Lambda environment variables ([#25](https://github.com/hammerstonedev/sidecar/pull/25))
9+
410
## 0.2.0 - 2021-07-12
511

612
### Added

docs/functions/customization.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Note that your layers must be in the same AWS region as your Lambdas!
114114

115115
## Environment Variables
116116

117-
Some functions or layers may require configuration via Lambda environment variables. The Lambda runtime makes environment variables available to the code.
117+
Some functions or layers may require configuration via Lambda environment variables. The Lambda runtime will inject the environment variables so that they available to your handler code.
118118

119119
In this example below, we're providing a path to a font directory as an environment variable.
120120
```php
@@ -145,7 +145,7 @@ By default, Sidecar doesn't touch your Lambda's environment at all. Only when yo
145145

146146
Another important thing to note is that Sidecar sets your environment variables as a part of the _activation_ process, not the _deploy_ process. This means that the environment variables will be pulled from the machine that calls `sidecar:activate`.
147147

148-
For example, if you are sharing secrets with your Lambda, then the values passed to your Lambda will be equal to the ones on the machine that called `sidecar:activate`, not the one that called `sidecar:deploy`:
148+
For example, if you are sharing secrets with your Lambda, then the values passed to your Lambda will be equal to the ones on the machine that called `sidecar:activate`, not the one that called `sidecar:deploy`
149149

150150
```php
151151
class ExampleFunction extends LambdaFunction
@@ -171,6 +171,8 @@ class ExampleFunction extends LambdaFunction
171171
}
172172
```
173173

174+
This is obviously important when you are calling `deploy` and `activate` from different machines as a part of your Laravel application's deployment process. To read more about deployment strategies, check out the [deploying](deploying) section.
175+
174176
## Name
175177

176178
Your function has a `name` method that determines how Sidecar names your Lambda functions. By default it is based on the name and path of your PHP class. You are free to change this if you want, but you're unlikely to need to.

docs/functions/deploying.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,73 @@ php artisan sidecar:activate --env=production
9494

9595
To read more about environments, head to the [Environments section](../environments) of the docs.
9696

97+
## Setting Environment Variables
98+
99+
This is covered in the [Environment Variables](customization#environment-variables) section of the Customization docs, but we'll cover strategies around env vars and deployment here.
100+
101+
Some of your functions will require environment variables, either from your Laravel application or something completely distinct. In some cases, you may need to set a static variable so that some library will work [(LibreOffice example)](https://github.com/hammerstonedev/sidecar/issues/24):
102+
103+
```php
104+
// torchlight! {"summaryCollapsedIndicator": "{ ... }" }
105+
class ExampleFunction extends LambdaFunction
106+
{
107+
public function handler() // [tl! collapse:start]
108+
{
109+
//
110+
}
111+
112+
public function package()
113+
{
114+
//
115+
} // [tl! collapse:end]
116+
117+
public function variables()
118+
{
119+
return [
120+
'FONTCONFIG_PATH' => '/opt/etc/fonts',
121+
];
122+
}
123+
}
124+
```
125+
126+
Setting static variables like that is quite straightforward.
127+
128+
If, however, you want to share some secrets or environment variables _from your Laravel_ application, it will be important that you are sharing them from the correct environment.
129+
130+
Imagine the scenario where you want to share your AWS keys with your Lambda function:
131+
132+
```php
133+
// torchlight! {"summaryCollapsedIndicator": "{ ... }" }
134+
class ExampleFunction extends LambdaFunction
135+
{
136+
public function handler() // [tl! collapse:start]
137+
{
138+
//
139+
}
140+
141+
public function package()
142+
{
143+
//
144+
} // [tl! collapse:end]
145+
146+
public function variables()
147+
{
148+
return [
149+
'aws_key' => config('services.aws.key'),
150+
'aws_secret' => config('services.aws.secret'),
151+
];
152+
}
153+
}
154+
```
155+
156+
You pull your key and secret using the Laravel `config` function, which in turn likely delegates to the `env()` function.
157+
158+
Sidecar sets the environment variables _upon activation_. If you are deploying from CI and then activating from e.g. Vapor, you'll want to make sure you have those variables in the Vapor environment.
159+
160+
Environment variables are set before activation, and before any pre-warming takes place.
161+
162+
And remember! If Sidecar manages the environment variables for a function, it will clobber any changes you make in the AWS UI, so you cannot use both methods simultaneously.
163+
97164
## Reusing Package Files
98165

99166
If you're deploying your Sidecar functions every time you deploy your app, you will likely be deploying functions that have not changed at all.

0 commit comments

Comments
 (0)