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.
- fork and then clone this repository :
git clone ...
- cd to project directory npm root :
cd lambda-tu-exercise/hello-world
- install nodejs stuff :
npm i
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.
- SAM CLI - Install the SAM CLI
- Node.js - Install Node.js 10, including the NPM package management tool.
- Docker - Install Docker community edition
To build your application for the first time, run the following in your shell when in this project root :
lambda-tu-exercise$ sam build
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.
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
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