|
10 | 10 | use Hammerstone\Sidecar\Exceptions\SidecarException; |
11 | 11 | use Hammerstone\Sidecar\Results\PendingResult; |
12 | 12 | use Hammerstone\Sidecar\Results\SettledResult; |
| 13 | +use Illuminate\Support\Arr; |
13 | 14 | use Illuminate\Support\Str; |
14 | 15 |
|
15 | 16 | abstract class LambdaFunction |
@@ -197,6 +198,18 @@ public function runtime() |
197 | 198 | return 'nodejs14.x'; |
198 | 199 | } |
199 | 200 |
|
| 201 | + /** |
| 202 | + * The type of deployment package. Set to Image for container |
| 203 | + * image and set Zip for .zip file archive. |
| 204 | + * |
| 205 | + * @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-lambda-2015-03-31.html#createfunction |
| 206 | + * @return string |
| 207 | + */ |
| 208 | + public function packageType() |
| 209 | + { |
| 210 | + return $this->handler() === Package::CONTAINER_HANDLER ? 'Image' : 'Zip'; |
| 211 | + } |
| 212 | + |
200 | 213 | /** |
201 | 214 | * An array full of ARN strings. Totally optional. |
202 | 215 | * |
@@ -233,6 +246,7 @@ public function variables() |
233 | 246 | * If your file lived in a folder called "lambda", you can just prepend the |
234 | 247 | * path to your handler, leaving you with e.g. "lambda/image.generate". |
235 | 248 | * |
| 249 | + * @see https://hammerstone.dev/sidecar/docs/main/functions/handlers-and-packages |
236 | 250 | * @see https://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Lambda.LambdaClient.html#_createFunction |
237 | 251 | * @return string |
238 | 252 | */ |
@@ -320,17 +334,29 @@ public function makePackage() |
320 | 334 | */ |
321 | 335 | public function toDeploymentArray() |
322 | 336 | { |
323 | | - return [ |
| 337 | + $config = [ |
324 | 338 | 'FunctionName' => $this->nameWithPrefix(), |
325 | 339 | 'Runtime' => $this->runtime(), |
326 | 340 | 'Role' => config('sidecar.execution_role'), |
327 | 341 | 'Handler' => $this->handler(), |
328 | | - 'Code' => $this->makePackage()->deploymentConfiguration(), |
| 342 | + 'Code' => $this->packageType() === 'Zip' |
| 343 | + ? $this->makePackage()->deploymentConfiguration() |
| 344 | + : $this->package(), |
329 | 345 | 'Description' => $this->description(), |
330 | 346 | 'Timeout' => (int)$this->timeout(), |
331 | 347 | 'MemorySize' => (int)$this->memory(), |
332 | 348 | 'Layers' => $this->layers(), |
333 | 349 | 'Publish' => true, |
| 350 | + 'PackageType' => $this->packageType(), |
334 | 351 | ]; |
| 352 | + |
| 353 | + // For container image packages, we need to remove the Runtime |
| 354 | + // and Handler since the container handles both of those |
| 355 | + // things inherently. |
| 356 | + if ($this->packageType() === 'Image') { |
| 357 | + $config = Arr::except($config, ['Runtime', 'Handler']); |
| 358 | + } |
| 359 | + |
| 360 | + return $config; |
335 | 361 | } |
336 | 362 | } |
0 commit comments