Authoring and deploying serverless applications

There are several choices for authoring and deploying serverless applications. We can use different tools for different use cases. For example, you can use the Lambda console for quick creation and iteration of simple apps. It is easy to use and has a built-in dev environment. If you have a more complex application, then you can define those with SAM and take advantage of tools built on top of SAM such as SAM Local for testing and debugging. You can plug SAM local into the IDE of your choice or use Cloud9 that is optimized for serverless applications and has SAM Local built-in. For incrementally rolling out new versions into production, you can build on SAM for CI/CD capabilities, including canary deployments.

The Lambda console now has the Cloud9 editor, which is optimized for serverless applications for quick author-test-debug iterations in serverless application development. It gives you an IDE-like experience. Realistically, this application lifecycle includes code check-in (after authoring and testing the code is completed) that kicks off the automated deployment process. This process picks up the code from the code repository, packages it, and builds the application. It then tests and deploys it in the production environment.

Using AWS Lambda console to author and test Lambda functions:

  1. Log in to the Management Console and go to the Lambda console. Click on Create a function button:
  1. We have shown the process of creating a Lambda function from scratch in Chapter 9, Implementing a Big Data Application. Here, we will select a pre-configured template for a Lambda function from the available blueprints:
  1. Search for the blueprint by entering hello-world in the filter field:
  1. For simplicity, we choose hello-world-python3 as the blueprint here. Check on the radio button and click on the Configure button:
  1. Provide a name for the Lambda function (TestLambdaBlueprint). For Role select the Choose an existing role option and then select LambdaFullAccess as the Existing role (you should be more selective in your production environment to restrict access to only the resources required by this function):
  1. Scroll down to see the Lambda function code:
  1. Click on the Create function button:
  1. You should see the message as shown to confirm the successful creation of the Lambda function:
  1. The view you land on contains function graph or the designer view. It is a visualization of what flows into your Lambda function and what flows out of it. You can see the event sources that are configured to trigger the function and also the downstream resources the function has permissions to access. The function is displayed in the middle: 
  1. On the left of the function box, you can see the list of triggers that are added to the function. We can click on a trigger from the list located in the left pane and that particular resource is added as a trigger. Click on API Gateway in the list of triggers:
  1. If you scroll down further at this stage, you will see that the panel below also changes accordingly to allow you to configure the newly added trigger as shown: 
  1. On the right of the function box are the resources the function can access. The CloudWatch logs are added by default to all functions, so that your function can emit logs to CloudWatch. By clicking on the right, you can see the details by resources and actions the function can perform, on which resources. Click on S3 to see the resource and permitted actions on them:
  1. Click on the By action link to see the details by permitted actions against the resources:
  1. Scroll further down to see the source code of the function. You can see all the files in the deployment package in the left pane:
>
  1. Press Cmd+Shift+F on Mac (or Ctrl+Shift+F on Windows) to go into a full-screen mode for an IDE-like experience:
  1. Next, we will define a test event for testing our function. You can create multiple test events and persist them. Click on Test and select Configure Events from the drop-down menu:
  1. Create the Test Event as shown:
  1. Click on Test to execute the Lambda function. You will see the response right below the code window. Some important metrics are also displayed as shown:
  1. Scroll back up to the Designer section and click on the Monitoring tab:
  1. In Monitoring view, there are interactive graphs that allow you to zoom into and out off any time frame and jump to the logs or the metrics for that time frame:
  1. In the Duration pane, select the period during which you executed the Test events. The view changes as shown:
  1. Click on the Jump to Logs link to view the CloudWatch logs for that time period:
  1. Next, from the Actions menu, select the Export function option:
  1. Click on the Download AWS SAM file button and then on the Download deployment package button. The deployment package essentially contains your function's source code in this example. We will discuss the contents of the SAM file in a later section:
  1. From the Actions menu, select the Delete function option:
  1. Click on Delete to confirm the deletion:
  1. You should see the following message after the function has been deleted successfully:
..................Content has been hidden....................

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