@@ -15,50 +15,59 @@ Deploy to Serverless AWS Lambda with BrefPHP
15
15
Overview
16
16
--------
17
17
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.
19
21
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>`_.
24
27
25
28
Setup Bref deployment with mongodb extension
26
29
--------------------------------------------
27
30
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
30
40
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
33
46
34
47
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
40
48
41
49
Replace the contents of ``index.php`` with the following:
42
50
43
51
.. literalinclude:: /examples/serverless-bref/index.php
44
52
:language: php
45
53
46
54
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).
49
57
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}
54
70
55
- functions:
56
- api:
57
- handler: index.php
58
- runtime: php-83-fpm
59
- layers:
60
- - ${bref-extra:mongodb-php-83}
61
- ```
62
71
63
72
Deploy the application
64
73
@@ -88,18 +97,18 @@ https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/
88
97
89
98
Update the serverless.yml file to pass the environment variable ``MONGODB_URI``
90
99
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
+
96
106
97
107
The value can be found in "Atlas > Deployment > Database > Connect". Select "3. AWS IAM".
98
108
You can remove the ``<AWS access key>:<AWS secret key>`` part from the URI, the
99
109
AWS SDK embedded in the MongoDB PHP Extension will request the metadata endpoint
100
110
to retrieve the credentials.
101
111
102
- ```
103
- MONGODB_URI=mongodb+srv://cluster0.abcdefg.mongodb.net/ serverless deploy
104
- ```
112
+ .. code-block:: bash
105
113
114
+ MONGODB_URI=mongodb+srv://cluster0.abcdefg.mongodb.net/ serverless deploy
0 commit comments