DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Building a Serverless Application on AWS With AWS SAM
  • Alexa Skill With Python
  • Alexa Skill With Node.js
  • Alexa Skill With TypeScript

Trending

  • Load Testing Essentials for High-Traffic Applications
  • Breaking Free from ZooKeeper: Why Kafka’s KRaft Mode Matters
  • A Keycloak Example: Building My First MCP Server Tools With Quarkus
  • Reducing Hallucinations Using Prompt Engineering and RAG
  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 
Vaquar Khan user avatar
Vaquar Khan
·
Feb. 12, 19 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
59.3K Views

Join the DZone community and get the full member experience.

Join For Free

 


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.

  • It lets you develop and test your AWS Lambda functions locally with SAM Local and Docker.
  • It lets you simulate function invocations from known event sources like Amazon Simple Storage Service (S3), Amazon DynamoDB, Amazon Kinesis, Amazon Simple Notification Service (SNS), and more.
  • It lets you start a local Amazon API Gateway from a SAM template, and quickly iterate on your functions with hot-reloading.
  • It lets you quickly validate your SAM template and even integrate that validation with linters or IDEs.
  • It provides interactive debugging support for your Lambda functions.

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



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



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.


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


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


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
  • Alexa Skill With Python
  • Alexa Skill With Node.js
  • Alexa Skill With TypeScript

Partner Resources

×

Comments

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: