|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: Setup |
| 4 | +permalink: /setup/ |
| 5 | +--- |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +In order to start to use [lambda-layer-canvas-nodejs](https://github.com/charoitel/lambda-layer-canvas-nodejs) published on [AWS Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs), you must have your AWS account with following services available: |
| 10 | + |
| 11 | +- [AWS Serverless Application Repository](https://aws.amazon.com/serverless/serverlessrepo) |
| 12 | +- [AWS Lambda](https://aws.amazon.com/lambda) |
| 13 | + |
| 14 | +## Serverless application deployment |
| 15 | + |
| 16 | +Once you have your AWS account ready, there are two ways to deploy [lambda-layer-canvas-nodejs](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs) and make it available in your AWS Lambda console: |
| 17 | + |
| 18 | +- [Deploy through AWS Serverless Application Repository](#deploy-through-aws-serverless-application-repository) |
| 19 | +- [Deploy through AWS Lambda console](#deploy-through-aws-lambda-console) |
| 20 | + |
| 21 | +### Deploy through AWS Serverless Application Repository |
| 22 | + |
| 23 | +1. Open https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs |
| 24 | +2. Click **Deploy** button |
| 25 | +3. Login to your AWS account if you haven't login yet |
| 26 | +4. Edit **_Name_** (Optional) |
| 27 | +5. Click **Deploy** button |
| 28 | +6. Deployment is started and in progress |
| 29 | +7. Check your AWS Lambda console once the deployment is completed |
| 30 | + |
| 31 | +### Deploy through AWS Lambda console |
| 32 | + |
| 33 | +1. Login to your AWS account and open your AWS Lambda console |
| 34 | +2. Click **Create application** button |
| 35 | +3. Select **_Serverless application_** |
| 36 | +4. Input `lambda-layer-canvas-nodejs` into search box and press _Enter_ key |
| 37 | +5. Click on the title of `lambda-layer-canvas-nodejs` card |
| 38 | +6. Edit **_Name_** (Optional) |
| 39 | +7. Click **Deploy** button |
| 40 | +8. Deployment is started and in progress |
| 41 | +9. Check your AWS Lambda console once the deployment is completed |
| 42 | + |
| 43 | +### Using canvas layer |
| 44 | + |
| 45 | +After the deployment is completed, you may refer [usage example](/lambda-layer-canvas-nodejs/{% link 01-use.md %}) and follow the example where a Lambda function uses the canvas layer to generate PNG graphic with colored text and circle rendered. |
| 46 | + |
| 47 | +## Setup environment to build the layer |
| 48 | + |
| 49 | +Alternately, you may setup your own environment to build the layer according to your specific needs. When using the layer with nodejs-18.x in Amazon Linux, it requires glibc-2.28, meanwhile, compiling glibc-2.28 requires make-4.x or later[^1]. |
| 50 | + |
| 51 | +```console |
| 52 | +$ wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz |
| 53 | +$ tar -xzvf make-4.3.tar.gz |
| 54 | +$ cd make-4.3/ |
| 55 | +$ ./configure --prefix=/usr |
| 56 | +$ make |
| 57 | +$ make install |
| 58 | +``` |
| 59 | +Once make-4.x or later is ready, we may start to compiling glibc-2.28 on Amazon Linux. However, during `make install` there would be an error due to `cannot found -lnss_test2` which could be ignored[^2]. |
| 60 | + |
| 61 | +```console |
| 62 | +$ wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz |
| 63 | +$ tar -xzvf glibc-2.28.tar.gz |
| 64 | +$ cd glibc-2.28 |
| 65 | +$ mkdir build && cd build |
| 66 | +$ ../configure --prefix=/usr --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin |
| 67 | +$ make |
| 68 | +$ make install |
| 69 | +... |
| 70 | +/usr/bin/ld: cannot find -lnss_test2 |
| 71 | +collect2: error: ld returned 1 exit status |
| 72 | +Execution of gcc -B/usr/bin/ failed! |
| 73 | +... |
| 74 | +``` |
| 75 | + |
| 76 | +To test if the installation of the compiled glibc-2.28 is success or not, we may check if `GLIBC_2.28` is enabled[^1] [^2]. |
| 77 | + |
| 78 | +```console |
| 79 | +$ ls -l /lib64/libc.so.6 |
| 80 | +lrwxrwxrwx 1 root root 12 Jul 3 15:14 /lib64/libc.so.6 -> libc-2.28.so |
| 81 | +$ strings /lib64/libc.so.6 | grep GLIBC |
| 82 | +... |
| 83 | +GLIBC_2.22 |
| 84 | +GLIBC_2.23 |
| 85 | +GLIBC_2.24 |
| 86 | +GLIBC_2.25 |
| 87 | +GLIBC_2.26 |
| 88 | +GLIBC_2.27 |
| 89 | +GLIBC_2.28 |
| 90 | +GLIBC_PRIVATE |
| 91 | +... |
| 92 | +``` |
| 93 | + |
| 94 | +Once your environment is ready, you may execute the build layer script, ``` build-layer.sh ```, to build the layer and deploy through the AWS Lambda console. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +[^1]: [Centos 7 升级 Glibc-2.28](https://cloud.tencent.com/developer/article/2021784) |
| 99 | +[^2]: [CentOS 7.6 编译安装最新版本glibc2.30 实录](https://www.jianshu.com/p/1070373a50f6) |
0 commit comments