Use Lambda to deploy serverless functions in DuploCloud
Lambda is a serverless computing platform provided by AWS that allows you to run code without provisioning or managing servers. It enables you to build and run applications in response to events or triggers from Lambda Functions.
Lambda Functions are event-driven and designed to perform small, specific tasks or functions. They can be written in supported programming languages such as Python, JavaScript (Node.js
), Java, C#, PowerShell, or Ruby. Once you create a Lambda function, you can configure it to respond to various types of events, such as changes in data stored in an Amazon S3 bucket, updates in an Amazon DynamoDB table, incoming HTTP requests via Amazon API Gateway, or custom events triggered by other AWS services.
Using Lambda, you write your code and upload it to AWS. Lambda executes and scales the code as needed, abstracting away the underlying infrastructure, and allowing you to focus on writing the actual business logic of your application. Lambda Functions are the principal resource of the Lambda serverless platform.
Use CI/CD GitHub Actions to update Lambda functions with images or S3 bucket updates.
In a Zip file, the Lambda Function code resides at the root of the package. If you are using a virtual environment, all dependencies should be packaged.
Refer to the AWS documentation for detailed instructions on how to generate the package, using tools such as Zappa and Serverless.
Use JIT to access the AWS Console.
Upload the Zip package in the AWS Console.
In the DuploCloud Portal, navigate to Cloud Services -> Serverless.
Click the Lambda tab. The Lambda Function page displays.
Click Add. The Create a Lambda Function page displays.
In the Name field, enter the name of your Lambda Function.
In the Description field, enter a useful description of the function.
From the Package Type list box, select Zip. For type Image, see the Configure Lambda with Container Images topic.
In the Runtime field, enter the runtime for your programming language.
From the the Architecture list box, select the correct Lambda Architecture.
To allocate a temporary file share, enter the value in megabytes (MB) in the Ephemeral Storage field. The minimum value is 512; the maximum value is 10240.
In the Function Handler field, enter the method name that Lambda calls to execute your function.
In the S3 Bucket list box, select an existing S3 bucket.
In the Function Package field, enter the name of the Zip package containing your Lambda Function.
In the Dead Letter Queue list box, select an Amazon Simple Queue Service (SQS) queue or Amazon Simple Notification Service (SNS) topic.
Click Submit. The Lambda Function is created.
On the Lambda Function page, from the Name column, select the function you created.
From the Actions menu, click Console. You are redirected to the AWS Console.
Test the function using the AWS Console.
DuploCloud enables you to create a classic micro-services-based architecture where your Lambda function integrates with any resource within your Tenant, such as S3 Buckets, Dynamo database instances, RDS database instances, or Docker-based microservices. DuploCloud implicitly enables the Lambda function to communicate with other resources but blocks any communication outside the Tenant, except Elastic Load Balancers (ELB).
To set up a trigger or event source, create the resource in the DuploCloud Portal. You can then trigger directly from the resource to the Lambda function in the AWS console menu of your Lambda function. Resources can be S3 Buckets, API gateways, DynamoDB database instances, and so on.
Passing secrets to a Lambda function can be done in much the same manner as passing secrets to a Docker-based service using Environmental Variables. For example, you can create a relational database from the Cloud Services -> Database -> RDS menu in DuploCloud, providing a Username and Password. In the Lambda menu, supply the same credentials. No secrets need to be stored in an AWS Key Vault, a Git repository, and so on.
To update the code for the Lambda function:
Create a new Zip package with a different name and upload it in the S3 bucket.
Select the Lambda Function (with the updated S3 Bucket). From the Actions menu, click Edit.
Enter the updated Name of the Lambda Function.
Use the Image Configuration field to update an additional configuration parameter.
Click Submit.
Using Container Images to configure Lambda
Create and Build your Lambda code using DockerFile
. Refer to the AWS documentation for detailed instructions on how to build and test container Images.
In the DuploCloud Portal, navigate to Cloud Services -> Storage.
Click the ECR Repository tab. The ECR Repository page displays.
Click Add. The Create an ECR Repository page displays.
In the ECR Repository Name field, enter the ECR Repository Name.
Click Create.
Login to ECR
Tag the images you have built.
Push the images to the ECR Repository that you created.
Refer to the AWS Documentation for more details about uploading Container Images.
In the DuploCloud Portal, navigate to Cloud Services -> Serverless.
Click the Lambda tab. The Lambda Function page displays.
Click Add. The Create a Lambda Function page displays.
In the Name field, enter the name of your Lambda Function.
In the Description field, enter a useful description of the function.
From the Package Type list box, select Image. For type Zip, see the Lambda Functions topic.
In the Image URL field, enter the URL of the image.
Click Submit. The Lambda function is created.
On the Lambda Function page, from the Name column, select the function you created.
From the Actions menu, click Console. You are redirected to the AWS Console.
Test the function using the AWS Console.
Package code libraries for sharing with Lambda Functions
A Lambda Layer is a Zip archive that can contain additional code or other content. A Lambda Layer may contain libraries, a custom runtime, data, or configuration files.
Lambda Layers provide a convenient and effective way to package code libraries for sharing with Lambda functions in your account. Using layers can help reduce the size of uploaded archives and make it faster to deploy your code.
You must add a Key/Value pair in the DuploCloud Portal's System Config settings to display Lambda Layers in DuploCloud.
In the DuploCloud Portal, navigate to Administrator -> System Settings.
Click the System Config tab.
Click Add. The Add Config pane displays.
From the Config Type list box, select Other. The Other Config Type field displays.
In the Other Config Type field, enter AppConfig.
In the Key field, enter ListAllLambdaLayers.
In the Value field, enter True.
Click Submit. The Key/Value pair is displayed in the System Config tab.
After you set ListAllLambdaLayers to True:
Layer names prefixed with DUPLO-
display for all Tenants in the DuploCloud Portal.
Layer names prefixed with DUPLOSERVICES-
display in the appropriate Tenant.
Before you add a Lambda Layer, you must have defined at least one Lambda Function.
In the DuploCloud Portal, navigate to Cloud Services -> Serverless.
In the Lambda tab, select the Lambda Function to which you want to add Lambda Layers.
Click the Actions menu and select Edit. The Edit Lambda Function page displays.
In the Layers area, click the + button. The Add Lambda Layer pane displays.
From the Layer list box, select the Lambda Layer to add.
From the Version list box, select the layer version.
Click Add Layer. The layer you added is displayed in the Layers area of the Edit Lambda Function page.
Optionally, enter an Image Configuration. Refer to the informational ToolTip ( ) for examples.