Skip to content

Commit f5f0194

Browse files
committed
-
1 parent b2fab0c commit f5f0194

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

docs/tutorial/serverless.txt

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,59 @@ Deploy to Serverless AWS Lambda with BrefPHP
1515
Overview
1616
--------
1717

18-
BrefPHP allows to deploy PHP applications on AWS Lambda.
18+
BrefPHP allows to deploy serverless PHP applications on AWS Lambda.
19+
In this tutorial, you will deploy a simple PHP application with the MongoDB PHP extension,
20+
and connect to an Atlas cluster using AWS IAM authentication.
1921

20-
Codecs are used to decode BSON documents into PHP objects, and encode PHP objects into BSON documents. In contrast to
21-
other methods (e.g. type maps), codecs allow for greater customization and handling of different data types. They
22-
separate logic for BSON encoding and decoding from the domain classes, which also enables BSON to be decoded into plain
23-
old PHP objects.
22+
Pre-requisites
23+
--------------
24+
25+
Before you begin, you must install BrefPHP on your machine. You can follow the
26+
`official documentation to setup BrefPHP <https://bref.sh/docs/setup>`_.
2427

2528
Setup Bref deployment with mongodb extension
2629
--------------------------------------------
2730

28-
Follow the Bref setup tutorial to install serverless and configure AWS credentials.
29-
https://bref.sh/docs/setup
31+
Start by creating a new directory for your project and install the required dependencies.
32+
This project will be a bare minimum PHP web application that connects to a MongoDB cluster,
33+
no framework is used, but you can adapt the code to your needs.
34+
35+
.. code-block:: bash
36+
mkdir bref-mongodb-app && cd bref-mongodb-app
37+
composer init
38+
composer require bref/bref bref/extra-php-extensions
39+
vendor/bin/bref init
3040

31-
Init a new application
32-
https://bref.sh/docs/default/getting-started
41+
By default, BrefPHP will create a simple web application that renders a web page.
42+
To validate the deployment, you can start by deploying the default application.
43+
44+
.. code-block:: bash
45+
serverless deploy
3346

3447

35-
mkdir bref-mongodb-app
36-
cd bref-mongodb-app
37-
composer init
38-
composer require bref/bref bref/extra-php-extensions
39-
vendor/bin/bref init
4048

4149
Replace the contents of ``index.php`` with the following:
4250

4351
.. literalinclude:: /examples/serverless-bref/index.php
4452
:language: php
4553

4654

47-
Bref provide a Lambda layer with PHP and some very common extensions. Additional extensions are provided
48-
by the package [bref/extra-php-extension](https://github.com/brefphp/extra-php-extensions).
55+
BrefPHP provides a Lambda layer with PHP and some very common extensions.
56+
Additional extensions are provided by the package [bref/extra-php-extension](https://github.com/brefphp/extra-php-extensions).
4957

50-
```yaml
51-
plugins:
52-
- ./vendor/bref/bref
53-
- ./vendor/bref/extra-php-extensions
58+
.. code-block:: yaml
59+
60+
plugins:
61+
- ./vendor/bref/bref
62+
- ./vendor/bref/extra-php-extensions
63+
64+
functions:
65+
api:
66+
handler: index.php
67+
runtime: php-83-fpm
68+
layers:
69+
- ${bref-extra:mongodb-php-83}
5470

55-
functions:
56-
api:
57-
handler: index.php
58-
runtime: php-83-fpm
59-
layers:
60-
- ${bref-extra:mongodb-php-83}
61-
```
6271

6372
Deploy the application
6473

@@ -88,18 +97,18 @@ https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/
8897

8998
Update the serverless.yml file to pass the environment variable ``MONGODB_URI``
9099

91-
```yaml
92-
provider:
93-
environment:
94-
MONGODB_URI: ${env:MONGODB_URI}
95-
```
100+
.. code-block:: yaml
101+
102+
provider:
103+
environment:
104+
MONGODB_URI: ${env:MONGODB_URI}
105+
96106

97107
The value can be found in "Atlas > Deployment > Database > Connect". Select "3. AWS IAM".
98108
You can remove the ``<AWS access key>:<AWS secret key>`` part from the URI, the
99109
AWS SDK embedded in the MongoDB PHP Extension will request the metadata endpoint
100110
to retrieve the credentials.
101111

102-
```
103-
MONGODB_URI=mongodb+srv://cluster0.abcdefg.mongodb.net/ serverless deploy
104-
```
112+
.. code-block:: bash
105113

114+
MONGODB_URI=mongodb+srv://cluster0.abcdefg.mongodb.net/ serverless deploy

0 commit comments

Comments
 (0)