Serverless Deployment: Deploying Your App to AWS Lambda
Written by Sigal Zigelboim   
Tuesday, 27 June 2023
Article Index
Serverless Deployment: Deploying Your App to AWS Lambda
Add AWS Resources

Serverless computing offers a powerful and scalable way of deploying applications to the cloud. By using AWS Lambda, developers can focus on writing code instead of managing infrastructure. Here we go through the steps of deploying an application to AWS Lambda using the Serverless Framework.   

Serverless sq 

What Is Serverless Deployment?

Serverless deployment is a form of cloud computing where the cloud provider manages the computing infrastructure and automatically provisions resources as needed, without requiring the user to provision or maintain servers. This allows development teams to focus on writing application code and implementing deployment without worrying about managing servers, scaling or configuring the infrastructure. Serverless deployment can also offer several benefits for microservices architectures, as it can enhance scalability, cost-efficiency, and operational simplicity.

There are two main types of serverless deployment models: Backend-as-a-Service (BaaS) and Function-as-a-Service (FaaS).

  • BaaS provides pre-built, managed backend services such as databases, authentication, push notifications, and storage. Examples of BaaS providers include Firebase, AWS Amplify, and Parse.
  • FaaS allows developers to deploy code in the form of small, single-purpose functions that are triggered in response to specified events, such as user requests or changes to data. These functions are automatically scaled and executed based on the relevant events, and developers only pay for the computing time they use. Examples of FaaS providers include AWS Lambda, Google Cloud Functions, and Azure Functions.

What Are AWS Lambda Applications?

AWS Lambda is a serverless compute service offered by Amazon Web Services that allows developers to run application code without managing or provisioning servers. Developers can leverage Lambda to construct serverless applications that respond to events, including data changes, user requests, or incoming messages.

AWS Lambda applications are composed of at least one Lambda function and any associated resources, such as databases, storage, or APIs. These applications are typically deployed using one of several tools provided by AWS, such as the Serverless Application Repository, CloudFormation, AWS CLI, or AWS SAM CLI:

  • The Serverless Application Repository is a public repository of serverless applications that can be easily deployed to an AWS account. Developers can find pre-built applications or share their own, making it easy to reuse and customize existing applications.

  • CloudFormation is a service that allows developers to create and manage AWS resources using a template-based approach. Developers can use CloudFormation to define their serverless application and deploy it to an AWS account.

  • The AWS CLI is a command-line interface that allows development teams to interact with AWS services. Developers can use this CLI to create, deploy, and manage serverless applications with Lambda functions and associated resources.

  • The AWS SAM CLI facilitates the use of AWS SAM (Serverless Application Model). It is a command-line interface tool that makes it easy to build, test, and deploy serverless applications SAM is an open framework for developing serverless applications that extends Amazon CloudFormation to provide a simplified way of defining the Amazon API’s Gateway APIs, Amazon DynamoDB tables, and Lambda functions, needed by serverless applications.

Creating an AWS Lambda Application: Step by Step

To complete the following tutorial, you’ll need to create these resources:

  • Application: This includes a Lambda function, AWS SAM template, and build specification. 

  • Code pipeline: This connects AWS resources to implement continuous delivery.

  • Git repository: The repository should be in AWS CodeCommit. 

  • Event trigger: A rule that specifies the CloudWatch event that triggers the delivery pipeline. 

  • CodeBuild artifact: This project that retrieves source code from the code pipeline to package the application.

  • Deployment configuration: This stage of the pipeline determines which actions deploy a new version of the application based on the SAM template using CloudFormation.

  • S3 bucket: An Amazon S3 bucket that stores the deployment artifact.

  • IAM roles: Each pipeline stage must have roles allowing it to control resources. 

Create the Application

The first step is to build a Lambda application which is a CloudFormation stack that includes a Lambda function alongside the supporting AWS resources. You can use the Lambda console to build the application:

  1. Go to Applications on the Lambda console and select Create application.

  2. Select the Author from scratch option.

  3. Specify the application configuration, including the app’s name (my-app), runtime (Node.js version), roles and permissions, repository, and source control service (AWS CodeCommit). Note: Please make sure there is no existing repository with name my-app-repo - otherwise application creation will fail.

  4. Click on Create and Lambda will build your pipeline and associated resources. It will commit the application code to your chosen Git repository.

  5. You can view the newly created resources under Overview.

LA1

Invoke the Lambda Function

After completing the deployment, you can invoke your application’s Lambda function from the console:

  1. Select the application (my-app) on the Applications page in the Lambda console.

  2. Go to Resources and select helloFromLambdaFunction.

  3. Click on Test and set up the test event, including the event’s name and body. Click on Create to build the test.

  4. Select Test and the console will run the selected function and display the test result. 

  5. You can view the details of the execution and output by expanding the test’s Details section.

LA2



Last Updated ( Wednesday, 28 June 2023 )