Creating the Lambda

We will create a Lambda similar to the simple greeting Lambda with plain old Java objects (POJOs) that we used in Chapter 1Getting Started with Serverless Computing on AWS. We will first use the CLI, and then a CloudFormation template, but with a few changes, which as follows:

  1. Add a field (time) to the HandlerRequest POJO, to represent the query parameter time (for example, Morning). The POJO already has a parameter, name, which represents the path parameter {name}.
  2. Modify the handleRequest method to use both of the parameters passed within JSON to generate the greeting message. If a value is not provided for a param, we will add a default value.
  3. We will also make a change to the previous CloudFormation template (lambda-with-pojos-cf-template.yml) by adding the Outputs component to the template, to export our Lambda's name, which will then be referred to from the API Gateway CloudFormation template through cross-stack reference:
Outputs:
LambdaOutput:
Description: 'Lambda For API Gateway Reference'
Value: !Ref MyLambdaFunction
Export:
Name: LambdaForApiGateway
  1. Create the stack by using the create-stack sub-command, and verify the stack by using the describe-stacks sub-command. The complete template and commands are available in the code files.
We will use the exported stack name LambdaForApiGateway later in this recipe from another template. We won't be able to delete a CloudFormation stack until all of the referenced stacks are deleted.
..................Content has been hidden....................

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