1
- ============================================
1
+ ==============================
2
2
Deploy to AWS Lambda with Bref
3
- ============================================
3
+ ==============================
4
4
5
5
.. default-domain:: mongodb
6
6
@@ -15,28 +15,28 @@ Deploy to AWS Lambda with Bref
15
15
Overview
16
16
--------
17
17
18
- `Bref <https://bref.sh>` allows to deploy serverless PHP applications on AWS Lambda.
18
+ `Bref <https://bref.sh>`_ allows to deploy serverless PHP applications on AWS Lambda.
19
19
In this tutorial, you will deploy a simple PHP application with the MongoDB PHP extension,
20
20
and connect to an Atlas cluster using AWS IAM authentication.
21
21
22
22
Prerequisites
23
23
--------------
24
24
25
25
Before you begin, you must install Bref on your machine. You can follow the
26
- `official documentation to setup bref <https://bref.sh/docs/setup>`_.
26
+ `official documentation to setup Bref <https://bref.sh/docs/setup>`_.
27
27
28
28
Install the MongoDB extension
29
29
-----------------------------
30
30
31
31
By default, the bref layer is compiled with PHP and a few extensions. Additional extensions
32
32
are provided in additional layers.
33
33
34
- Start by creating a new directory for your project and install the required mongodb
35
- and bref dependencies. This project will be a bare minimum PHP web application that
36
- connects to a MongoDB cluster. No framework is used, but you can adapt the code to
37
- your needs.
34
+ Start by creating a new directory for your project and install the required MongoDB
35
+ and Bref dependencies. This project will be a bare minimum PHP web application that
36
+ connects to a MongoDB cluster.
38
37
39
38
.. code-block:: bash
39
+
40
40
mkdir bref-mongodb-app && cd bref-mongodb-app
41
41
composer init
42
42
composer require bref/bref bref/extra-php-extensions
@@ -47,10 +47,12 @@ The file ``index.php`` has been created. To validate the deployment, you can sta
47
47
by deploying this default application.
48
48
49
49
.. code-block:: bash
50
+
50
51
serverless deploy
51
52
53
+
52
54
Bref provides a Lambda layer with PHP and some very common extensions.
53
- Additional extensions are provided by the package `bref/extra-php-extension <https://github.com/brefphp/extra-php-extensions>`.
55
+ Additional extensions are provided by the package `bref/extra-php-extension <https://github.com/brefphp/extra-php-extensions>`_ .
54
56
55
57
.. code-block:: yaml
56
58
@@ -67,16 +69,17 @@ Additional extensions are provided by the package `bref/extra-php-extension <htt
67
69
68
70
69
71
Let's try to use the MongoDB driver with this simple web page that list planets
70
- from the `sample dataset <https://www.mongodb.com/docs/atlas/sample-data/>`.
72
+ from the `sample dataset <https://www.mongodb.com/docs/atlas/sample-data/>`_ .
71
73
Replace the contents of ``index.php`` with the following:
72
74
73
- .. literalinclude:: /examples/lambda- aws/index.php
75
+ .. literalinclude:: /examples/aws-lambda /index.php
74
76
:language: php
75
77
76
78
77
79
Deploy the application
78
80
79
81
.. code-block:: bash
82
+
80
83
serverless deploy
81
84
82
85
@@ -89,7 +92,7 @@ Atlas supports passwordless authentication with AWS credentials. In any Lambda f
89
92
AWS sets environment variables that contains the access token and secret token with
90
93
the role assigned to deployed function.
91
94
92
- Set up `unified AWS Access <https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/>`
95
+ Set up `unified AWS Access <https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/>`_
93
96
94
97
1. Open the Lambda function in the AWS console
95
98
2. In "Configuration > Permission", copy the "Role name"
@@ -113,7 +116,7 @@ Update the ``serverless.yml`` file to pass the environment variable ``MONGODB_UR
113
116
114
117
115
118
The value can be found in "Atlas > Deployment > Database > Connect". Select "3. AWS IAM".
116
- You can remove the ``<AWS access key>:<AWS secret key>`` part from the URI, the credentials
119
+ Remove the ``<AWS access key>:<AWS secret key>`` part from the URI, the credentials
117
120
will be read from environment variables.
118
121
119
122
.. code-block:: bash
0 commit comments