How to Create and Deploy a Lambda Function in AWS: A Complete Guide

Create Lambda Function

Create Lambda function and deploy

Here are the steps to create a Lambda function using the AWS Management Console:

Create Lambda function and deploy 2

Fill yours function infomation:

  • Select: Author from scratch
  • Function name: fill your function name. ex: LambdaFetchDataFunction
  • Runtime: Java11
  • Architecture: arm64
  • Advanced settings: Select Enable VPC
  • VPC: Choose VPC we are created at step 1
  • Subnets: Choose private-subnet
  • Security groups: recommend default

After fulfill choose Create function, Similar let continue create 3 functions like image below order: LambdaFetchDataFunction, LambdaDeleteDataFunction, LambdaFetchDataFunction

Create Lambda function and deploy 3

Config Detail For Each Function

Create Lambda function and deploy 3

After do that, we have 3 function, now click to LambdaFetchDataFunction Create Lambda function and deploy 3 To function working, we need upload code to lambda, click Upload From at Code tab.. Create Lambda function and deploy 3

We have 2 choices:

  • Upload the file directly .jar file, that we have built mvn clean package at step 3
  • Upload via S3 console and get a public URI and fill that

Create Lambda function and deploy 3

Next, we have to config runtime environment to lambda can execute correct function, Click Edit Create Lambda function and deploy 3

Patse Handle is: org.example.awsserverlessnoteapp.LambdaFetchDataFunction::handleRequest

Create Lambda function and deploy 3 Now, let’s inspect our source code. We have a class name LambdaFetchDataFunction, The class LambdaFetchDataFunction under package: org.example.awsserverlessnoteapp. The class LambdaFetchDataFunction has function handleRequest, that execute fetch data from DynamoDB Create Lambda function and deploy 3

Next we will click on the Configuration tab, click to Environment variables, we can configure multiple values here.

  • General configuration
  • Triggers
  • Permissions
  • Destinations
  • Function URL
  • Environment variables
  • Tags
  • VPC
  • Monitoring and operations tools
  • Concurrency
  • Asynchronous invocation
  • Code signing
  • RDS databases
  • File systems
  • State machines

Let’s click Edit and add 2 environment variables to it.

Key: AWS_DYNAMO_TABLE_NAME_VALUE, Value: note_tbl
Key: AWS_REGION_VALUE, Value: us-east-1

Similarly, set up the lambda function LambdaAddDataFunction,LambdaDeleteDataFunction according to the instructions above.

Conclusion:This comprehensive guide will walk you through the process of creating and deploying an AWS Lambda function. AWS Lambda enables you to run code in a serverless environment, eliminating the need for server management. Follow these steps to set up and deploy your Lambda function efficiently.