Git Product home page Git Product logo

lambda-tu-exercise's Introduction

Lambda functions unit testing made easy

First read this page and startup app, then see actual exercises on this page

This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders.

  • hello-world - Code for the application's Lambda function.
  • events - Invocation events that you can use to invoke the function.
  • hello-world/tests - Unit tests for the application code.
  • template.yaml - A template that defines the application's AWS resources.

If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit.
The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started.

How to :

1 - Get files and build modules

  1. fork and then clone this repository : git clone ...
  2. cd to project directory npm root : cd lambda-tu-exercise/hello-world
  3. install nodejs stuff : npm i

2 - Pre build the sample application

The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.

To use the SAM CLI, you need the following tools.

To build your application for the first time, run the following in your shell when in this project root :

lambda-tu-exercise$ sam build

3 - Use the SAM CLI to build and test locally

Build your application with the sam build command if big changes occurred.

lambda-tu-exercise$ sam build

The SAM CLI installs dependencies defined in hello-world/package.json, creates a deployment package, and saves it in the .aws-sam/build folder.

The SAM CLI can emulate your application's API. Use the sam local start-api to run the API locally on port 3000.

lambda-tu-exercise$ sam local start-api

Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2020-11-27 17:11:15  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

Finally, point your favourite browser to http://127.0.0.1:3000/hello and see the app running.

Unit tests

Tests are defined in the hello-world/tests folder in this project. Use NPM to install the Mocha test framework and run unit tests.

lambda-tu-exercise$ cd hello-world
hello-world$ npm install
hello-world$ npm run test


> [email protected] test /home/ben/Bureau/easiware/lambda-tu-exercise/hello-world
> mocha tests/unit/

  Testing /hello
    ✓ must return 200 with response when ANY event given
    ✓ must return 404 with correct response when INVALID event given
    ✓ must return 404 with correct response when NO event given


  3 passing (9ms)

This is another way to execute application, in controlled contexts

Resources

See the AWS SAM developer guide for an introduction to SAM specification, the SAM CLI, and serverless application concepts.

Next, you can use AWS Serverless Application Repository to deploy ready to use Apps that go beyond hello world samples and learn how authors developed their applications: AWS Serverless Application Repository main page

lambda-tu-exercise's People

Contributors

bensoille avatar snyk-bot avatar

Watchers

 avatar

Forkers

samyyy13

lambda-tu-exercise's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.