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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Join us tomorrow at 1 PM EST: "3-Step Approach to Comprehensive Runtime Application Security"
Save your seat
  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.

Vaquar Khan user avatar by
Vaquar Khan
·
Feb. 12, 19 · Tutorial
Like (4)
Save
Tweet
Share
53.17K 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.

Popular on DZone

  • How To Check Docker Images for Vulnerabilities
  • Bye Bye, Regular Dev [Comic]
  • How to Create a Real-Time Scalable Streaming App Using Apache NiFi, Apache Pulsar, and Apache Flink SQL
  • Kubernetes vs Docker: Differences Explained

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: