VOOZH about

URL: https://dzone.com/articles/run-aws-lambda-functions-locally-on-windows-machin

⇱ Run AWS Lambda Functions Locally on a Windows Machine


Related

  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Run AWS Lambda Functions Locally on a Windows Machine

Run AWS Lambda Functions Locally on a Windows Machine

Take a look at how you can run your AWS Lambda functions closer to home with the benefit of SAM Local.

By Feb. 12, 19 Β· Tutorial
Likes
Comment
Save
59.8K Views

Join the DZone community and get the full member experience.

Join For Free

 πŸ‘ Image


I was playing with AWS Lambda recently and found it pretty exciting. It's also cheap as serverless applications don’t require provisioning, maintaining, and administering servers, and AWS, in particular, is simple, easy-to-learn, and powerful. AWS Lambda supports Java, Go, PowerShell, Node.js, C#, Python, and Ruby languages. The biggest problem with using Lambda is that it does not allow inline editing for Java. In Java, you need to write the code in an editor and build a .jar or .zip deploy on the console.

As deployment is a complex, painful, and time-consuming process, the concern here is that when developers want to test the application after changing the code they have to, again and again, deploy the .jar to the AWS lambda console.

After spending a few hours with Lambda, I found SAM Local in AWS docs.

πŸ‘ SAM Local


SAM Local takes all the good parts of SAM and brings them to your local machine.

AWS SAM Local is a β€œCLI tool for local development and testing of Serverless applications.” It uses Docker to simulate a Lambda-like experience. The docs explain well how to get started, and the GitHub repo has lots of samples as well.

This tutorial shows you how to set up SAM Local on local Windows machine.

Prerequisites:

  • Docker
  • AWS Command Line Interface (AWS CLI)
  • (Pip only) Python 2.7 or Python 3.6
  • Java 8



Step 1: Download SAM local Windows Install SAM CLI using an MSI in either the 64 bit or 32 bit versions.

Step 2: Verify that the installation succeeded and version with the command below.

sam --version


πŸ‘ Image


Step 3: Write your lambda function or clone it from Github to run locally, making sure to add Template.yaml on the root level.

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Lambda Sample Project

Resources:

 Products:
 Type: AWS::Serverless::Function
 Properties:
 Handler: com.example.handler.LambdaHandler
 CodeUri: ./target/lambda-project-1.0-SNAPSHOT.jar
 Runtime: java8
 Timeout: 300
 Environment:
 Variables:
 ENVIRONMENT: "test"Events:
 ListProducts:
 Type: Api
 Properties:
 Path: /lambda
 Method: post


Step 4: Run Maven with the commands below.

mvn clean
mvn install


Step 5: The  sam local start-api command allows you to run your serverless application locally for quick development and testing. When you run this command in a directory that contains your serverless functions and your AWS SAM template, it creates a local HTTP server that hosts all of your functions.

sam local start-api


πŸ‘ Image


Run AWS Lambda Functions With AWS Toolkit Eclipse:

Prerequisites:

  • Java 8 and Python 2.7 and 3.6 and Docker should be installed in local.

You can also use Eclipse or STS 4 and add the Eclipse AWS toolkit.

πŸ‘ Image


Step 1: In the configured path where we have sam.exe, find the installation folder

πŸ‘ Image


Step 2: Write your lambda function or clone from Github and run locally.

πŸ‘ Image


First published on Linkedin.

AWS AWS Lambda Machine Command-line interface Sam (text editor)

Opinions expressed by DZone contributors are their own.

Related

  • Building a Serverless Application on AWS With AWS SAM
  • End-to-End Event Streaming With Kafka, Spring Boot and AWS SQS/SNS (Production-Ready Code Guide)
  • AWS Bedrock: The Future of Enterprise AI
  • Understanding Custom Authorization Mechanisms in Amazon API Gateway and AWS AppSync

Partner Resources

Γ—

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: