Skip to content

Commit 8ddfd65

Browse files
authored
Merge pull request #2069 from brefphp/improve-sdk-documentation
Replace #2016 "Add note on reducing vendor size for AWS SDK"
2 parents 4835a50 + 3ab2566 commit 8ddfd65

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

docs/deploy.mdx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ Instead, let's remove development dependencies and optimize Composer's autoloade
4141
composer install --prefer-dist --optimize-autoloader --no-dev
4242
```
4343

44-
<Callout>
45-
Using [aws/aws-sdk-php](https://github.com/aws/aws-sdk-php/tree/master/src/Script/Composer) or [google/apiclient](https://github.com/googleapis/google-api-php-client#cleaning-up-unused-services)? See the links for reducing deployment size by removing unused services
46-
</Callout>
47-
4844
Now is also the best time to configure your project for production, as well as build any file cache if necessary.
4945

5046
Once your project is ready, you can deploy via the following command:
@@ -62,6 +58,46 @@ Once your project is ready, you can deploy via the following command:
6258
</Tab>
6359
</Tabs>
6460

61+
### Reducing package size
62+
63+
AWS Lambda has a **250MB size limit** for deployed applications (unzipped). Large Composer dependencies can push your project over this limit and also lead to slower cold starts.
64+
65+
The most common offender is `aws/aws-sdk-php`: it ships clients for **every** AWS service, adding over 100MB to your vendor directory. If you only use a few services (e.g. S3, SQS, DynamoDB), you can remove the rest.
66+
67+
Add the following to your `composer.json`:
68+
69+
```json
70+
{
71+
"scripts": {
72+
"pre-autoload-dump": [
73+
"Aws\\Script\\Composer\\Composer::removeUnusedServices"
74+
]
75+
},
76+
"extra": {
77+
"aws/aws-sdk-php": [
78+
"Lambda",
79+
"S3",
80+
"Sqs",
81+
"DynamoDb"
82+
]
83+
}
84+
}
85+
```
86+
87+
Then run `composer install` (or `composer update`) to apply the changes. Adjust the list to keep only the AWS services your application actually uses. Note: `S3`, `Kms`, `SSO`, and `Sts` cannot be removed as they are required by the SDK core.
88+
89+
[Read more in the `aws/aws-sdk-php` documentation.](https://github.com/aws/aws-sdk-php/tree/master/src/Script/Composer)
90+
91+
<Callout type="info">
92+
As an alternative, you can replace `aws/aws-sdk-php` with [AsyncAws](https://async-aws.com/), a lighter SDK that only installs the services you need.
93+
</Callout>
94+
95+
Using `google/apiclient`? A similar approach is available: [see the documentation to remove unused Google API services](https://github.com/googleapis/google-api-php-client#cleaning-up-unused-services).
96+
97+
To further reduce deployment size, exclude non-essential files (tests, assets, node_modules) from the package. [Read more in the serverless.yml exclusions documentation.](environment/serverless-yml.mdx#exclusions)
98+
99+
If your application still exceeds the 250MB limit, you can [deploy via Docker images instead](deploy/docker.mdx).
100+
65101
## Environments
66102

67103
We can deploy the same application multiple times in completely separated environments (also called "stages" by the Serverless CLI).

docs/laravel/getting-started.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ At the moment, we deployed our local codebase to Lambda. When deploying for prod
7676

7777
Follow [the deployment guide](/docs/deploy.md#deploying-for-production) for more details about deploying in general.
7878

79+
<Callout type="warning">
80+
Most Laravel applications use `aws/aws-sdk-php` (pulled in by packages like SQS queues, S3 storage, etc.). This package is **very large** (100MB+) and can push your deployment over Lambda's 250MB size limit. Make sure to [remove unused AWS services](/docs/deploy.md#reducing-package-size) to reduce the deployment size.
81+
</Callout>
82+
7983
Specifically for Laravel, Bref will automatically cache the configuration on "cold starts". This means that you don't need to run `php artisan config:cache` before deploying.
8084

8185
<Callout type="warning">

docs/runtimes/function.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ You first need to install the AWS PHP SDK by running
248248
$ composer require aws/aws-sdk-php
249249
```
250250

251+
<Callout type="info">
252+
The `aws/aws-sdk-php` package is very large (100MB+). To avoid hitting Lambda's 250MB size limit, [remove unused AWS services from the package](/docs/deploy.md#reducing-package-size).
253+
</Callout>
254+
251255
```php
252256
$lambda = new \Aws\Lambda\LambdaClient([
253257
'version' => 'latest',

0 commit comments

Comments
 (0)