|
1 |
| -Prerequisites: |
2 |
| -- AWS SAM CLI |
3 |
| -- Docker daemon running |
4 |
| - |
5 |
| -Environment: |
6 |
| -- `LAMBDA_AWS_ROLE_ARN` |
7 |
| -- `LAMBDA_STACK_NAME` |
8 |
| -- `DRIVERS_ATLAS_GROUP_ID` |
9 |
| -- `MONGODB_URI` |
10 |
| -- `AWS_ACCESS_KEY_ID` |
11 |
| -- `AWS_SECRET_ACCESS_KEY` |
12 |
| -- `AWS_REGION` |
13 |
| - |
14 |
| -Function Setup: |
15 |
| - |
16 |
| -1. `sam init` and follow instructions for your language, creating a hello world example. |
17 |
| - |
18 |
| -2. Modify the generated function and template.yaml, renaming as needed, and add the |
19 |
| - following functionality: |
20 |
| - - Must create and cache a `MongoClient` during the init phase of the function. |
21 |
| - - For dynamic languages this is at module load time. |
22 |
| - - For static languages this can be done in the function constructor. |
23 |
| - - The MongoClient must get the uri from the `MONGODB_URI` environment variable. |
24 |
| - - The following events must be listened to on the client, and should be added and removed |
25 |
| - within the handler function itself. |
26 |
| - - command started |
27 |
| - - command succeeded |
28 |
| - - command failed |
29 |
| - - server heartbeat started |
30 |
| - - server heartbeat succeeded |
31 |
| - - server heartbeat failed |
32 |
| - - connection created |
33 |
| - - connection closed |
34 |
| - - The function itself must insert one document and delete that document |
35 |
| - - The function must return JSON with the average duration times of each suceeded |
36 |
| - event, the number of connections created and closed, and heartbeat count: |
37 |
| - ```json |
38 |
| - { |
39 |
| - "averageCommandSuceeded": 40, |
40 |
| - "averageHeartbeatSuceeded": 20, |
41 |
| - "openConnections": 1, |
42 |
| - "heartbeatCount": 10 |
43 |
| - } |
44 |
| - ``` |
45 |
| - - Update template.yaml to provide a default MONGODB_URI in the Globals section: |
46 |
| - ```yaml |
47 |
| - Globals: |
48 |
| - Function: |
49 |
| - Timeout: 10 |
50 |
| - Environment: |
51 |
| - Variables: |
52 |
| - MONGODB_URI: 'mongodb://127.0.0.1:27017' |
53 |
| - ``` |
54 |
| - |
55 |
| -3. Create env.json with the format: |
56 |
| - ```json |
57 |
| - { |
58 |
| - "Parameters": { |
59 |
| - "MONGODB_URI": "<uri to test>" |
60 |
| - } |
61 |
| - } |
62 |
| - ``` |
63 |
| - |
64 |
| -4. `sam build` from the project directory to build the function. |
| 1 | +AWS Lambda Testing |
| 2 | +------------------ |
65 | 3 |
|
66 |
| -5. `sam local invoke --env-vars ./env.json` to create the container and run the function locally. |
| 4 | +Running locally |
| 5 | +=============== |
67 | 6 |
|
68 |
| -Function Testing: |
69 |
| - |
70 |
| -1. Create an Atlas M10 sharded cluster. |
71 |
| - |
72 |
| -2. Get URI to connect to cluster. |
73 |
| - |
74 |
| -3. Set MONGODB_URI in the function environment. |
75 |
| - |
76 |
| -4. `sam build` |
77 |
| - |
78 |
| -5. Assume role DRIVERS-2384 |
79 |
| - |
80 |
| -6. `sam deploy ==stack-name ${LAMBDA_STACK_NAME}` --capabilities CAPABILITY_IAM --resolve-s3` |
| 7 | +Prerequisites: |
81 | 8 |
|
82 |
| -7. Get the function arn |
| 9 | +- AWS SAM CLI |
| 10 | +- Docker daemon running |
83 | 11 |
|
84 |
| -7. `aws lambda invoke --function-name <function arn> standard.json` |
| 12 | +Steps |
| 13 | +===== |
85 | 14 |
|
86 |
| -8. Sleep 30 seconds. |
| 15 | +- `sam build` from the `test/lambda`. |
87 | 16 |
|
88 |
| -7. `aws lambda invoke --function-name <function arn> standard.json` |
| 17 | +- `sam local invoke --parameter-overrides "MongoDbUri=mongodb://127.0.0.1:27017"` |
0 commit comments