Deployment

We can deploy lambda to AWS using two tools:

  • AWS CLI tool
  • Web AWS Console

The first is a little tedious, and in the next section of this chapter, you will see how to use the Serverless Framework to deploy an application consists of lambda functions. For this example, enter the AWS Console and go to the AWS Lambda product page. Click the Create Function button and, in the form that appears, enter the following values:

  • Name: minimal-lambda
  • Runtime: Choose Use custom runtime in function code or layer
  • Role: Choose Create a new role from one or more templates
  • Role name: minimal-lambda-role

This is what the form should look like when you've finished:

Click the Create function button, and while the function is being created, pack the binary to the zip file using the following command:

zip -j minimal-lambda.zip target/x86_64-unknown-linux-musl/debug/bootstrap

In the form that appears, choose Upload a .zip file in the Code entry type of the Function code section:

Choose the file and upload it using the form. When the archive with the Rust function is uploaded, the function is ready to be called. Click on the Test button, and you will see a form in which you can enter the testing request in JSON format:

Enter the following JSON in it:

{
"distribution": "uniform",
"parameters": {
"start": 0,
"end": 100
}
}

This is a serialized RngRequest value that generates random a value in the range 0-100 using uniform distribution. Enter uniform in the Event name field and click the Create button, and the testing prerequisites will be stored. Now you can choose this request in the drop-down list to the left of the Test button. Choose uniform value and click the Test button to see the result of the response:

Our microservice generated a value. If you click the Test button again, it will generate the next value. As you can see, there are log records printed by the simple_logger crate in the Log output section. And the execution of this function takes about 20 milliseconds.

The main benefit of AWS Lambda is access to all other AWS services. Let's create a more complex example that utilizes more services in order to show how to integrate lambda functions with other AWS infrastructure.

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

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