|
2 | 2 | title: Deploying a Lambda
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -# Deploying a Lambda |
| 5 | +## Using the template Makefile |
6 | 6 |
|
7 | 7 | To deploy your project to AWS Lambda, we have provided a `Makefile` to make your life easier.
|
8 |
| -Run `make` from the root of your project, and you will have a `build/function.zip` generated for you. |
9 | 8 |
|
10 |
| -Note that this uses [**Docker**](https://www.docker.com) underneath, so make sure you have it installed |
11 |
| -and set-up on your system. |
| 9 | +Run `make` from the root of your project, and you will have a [**Docker**](https://www.docker.com) image generated for you that is ready to be deployed onto AWS Lambda. |
12 | 10 |
|
13 |
| -## Manual deploy |
| 11 | +## Building the executable manually |
14 | 12 |
|
15 |
| -To build the `function.zip` file manually, you need to run these commands: |
| 13 | +You could also build the executable manually, but that is troublesome because it either needs to be static or you need to make sure to ship all library dependencies as well as build it on the same environment it's going to run on. |
16 | 14 |
|
17 |
| -```bash |
18 |
| -# Create the output `build` directory |
19 |
| -mkdir -p build |
20 |
| -# Perform a clean build of the project using docker |
21 |
| -# (In some cases `stack clean` is not needed, you can try removing it) |
22 |
| -stack clean --docker |
23 |
| -stack build --docker |
| 15 | +For simple executables without dependencies, you could just add the following to your `package.yaml`, build the `bootstrap` and ship it to AWS using a `.zip` file. |
24 | 16 |
|
25 |
| -# Copy the generated executable to the output path |
26 |
| -cp $(stack --docker path --local-install-root)/bin/bootstrap build |
27 |
| - |
28 |
| -# Create a `function.zip` file to upload |
29 |
| -cd build && zip function.zip bootstrap && rm bootstrap && cd .. |
30 |
| -``` |
31 |
| - |
32 |
| -## AWS Lambda Console |
33 |
| - |
34 |
| -In the AWS Lambda console select `Create function` and give your function a name, |
35 |
| -e.g. `myHaskellLambda`, and for the runtime select `'Provide your own bootstrap'`. |
36 |
| - |
37 |
| - |
38 |
| - |
39 |
| - |
40 |
| - |
41 |
| -Inside your function configuration, select `'Upload a .zip file'` for code entry type. |
42 |
| -Select the `function.zip` in the Function package. Change the Handler |
43 |
| -to `src/Lib.handler`. |
44 |
| - |
45 |
| -Remember to select `Save` to save your configuration. |
46 |
| - |
47 |
| - |
48 |
| - |
49 |
| - |
50 |
| -Next to the Test button select `'Configure test events'` and use the following JSON for |
51 |
| -a successful test. |
52 |
| - |
53 |
| - |
54 |
| - |
55 |
| - |
56 |
| -``` |
57 |
| -{ |
58 |
| -"personName": "Bobby", |
59 |
| -"personAge": 21 |
60 |
| -} |
61 |
| -``` |
62 |
| - |
63 |
| -For a test which captures the error and results in a failure use the following JSON. |
64 |
| - |
65 |
| -``` |
66 |
| -{ |
67 |
| -"personName": "Bobby", |
68 |
| -"personAge": -1 |
69 |
| -} |
70 |
| -``` |
71 |
| -After selecting the test you wish to run and pressing `Test` you will see the resul in the `Execution result` area. For successful execution the returned data will be the same as the input. |
72 |
| - |
73 |
| -In the failure case the returned data will be `'A person's age must be positive'`. |
74 |
| - |
75 |
| - |
76 |
| - |
77 |
| -Congratulations you have ran your first AWS Lambda using the Haskell runtime! |
| 17 | +```yaml |
| 18 | +ghc-options: |
| 19 | + .. other options |
| 20 | + - -O2 |
| 21 | + - -static |
| 22 | +cc-options: -static |
| 23 | +ld-options: -static -pthread |
| 24 | +``` |
0 commit comments