Creating AWS Lambda 

AWS Lambda is an AWS service to help you to build applications for a specific purpose. In this section, we will develop an AWS Lambda application. I will show how to develop AWS Lambda using Node.js.

Firstly, Node.js has to be installed on Raspberry Pi. Then, install AWS Greengrass Core SDK for Node.js. Based on the documentation, we should copy and paste node as nodejs6.10. You can do this with the following command:

$ sudo cp /usr/bin/node /usr/bin/nodejs6.10

Prepare the Lambda program sample from AWS Greengrass Core. You can find it at <greengrass_core_sdk_js>/samples/HELLOWORLD. Inside this folder, create the node_modules folder. Copy the aws-greengrass-core-sdk folder from AWS Greengrass Core SDK for Node.js into the node_modules folder, as shown in the following screenshot:

Then, compress all files within the HELLOWORLD folder. Make sure index.js is the root of the HELLOWORLD folder. If not, AWS Lambda will not recognize your Lambda application. Finally, we have the HelloWorld.zip file that contains the Lambda application. We will upload it on AWS Lambda.

Open AWS Lambda by opening a browser and navigating to https://console.aws.amazon.com/lambda. You should see the AWS Lambda dashboard after login.

Now you can proceed with the following steps to create your AWS Lambda function:

  1. Click on the Create a function button. You should see a form, as shown in the following screenshot:

Type greengrass so you can see the application samples for Greengrass.  Select greengrass-hello-world-nodejs by clicking on the checkbox. Then, click on the Author from scratch button.

  1. Fill in the function and role names. Select the Create new role from template(s) option for the role. When done, click on the Create function button.
  2. Now you should see the Lambda function dashboard. In the Function code section, select Upload a .ZIP file with runtime Node.js 6.10 and index.handler for the handler name.
  3. Click on the HelloWorld.zip file that we have prepared to upload the Lambda application:
  1. Then, click on the Save button to upload and load the Lambda program from the ZIP file. If successful, you should see Lambda program in Node.js. If it has failed, you will probably get error messages while uploading the ZIP file:
  1. Now we publish this AWS Lambda. Select Publish new version from the Actions drop-down list.
  2. After selecting, you should be asked to fill in the version description. Once done, click on the Publish button to publish AWS Lambda:

The next step is to deploy this service with our AWS Greengrass Core machine.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.237.201