Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/buildbreakdo/lambda-starter
AWS Lambda Starter Kit with latest Babel 7, Jest 24 and Webpack 4.
https://github.com/buildbreakdo/lambda-starter
api-gateway aws aws-lambda babel sam-local webpack
Last synced: 2 days ago
JSON representation
AWS Lambda Starter Kit with latest Babel 7, Jest 24 and Webpack 4.
- Host: GitHub
- URL: https://github.com/buildbreakdo/lambda-starter
- Owner: buildbreakdo
- License: mit
- Created: 2018-03-13T15:55:06.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T18:20:58.000Z (almost 2 years ago)
- Last Synced: 2023-03-02T11:17:05.971Z (almost 2 years ago)
- Topics: api-gateway, aws, aws-lambda, babel, sam-local, webpack
- Language: JavaScript
- Homepage:
- Size: 2.27 MB
- Stars: 26
- Watchers: 1
- Forks: 4
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Lambda Starter Kit
- to enable the latest JavaScript ES6 language features and simplification of code with the class syntax
- Webpack to bundle only production dependencies to a single file, watch for changes and eliminate dead code
- AWS Sam Local to emulate API Gateway locally so you can test your Lambda functions without deploying to AWS
- Jest to test and confirm code works during development and before deploying to production## Installation
```
cd YourLambdaFunctionDirectory
git clone [email protected]:buildbreakdo/aws-api-lambda.git .
npm install
```## Create
To ensure correct assignment of IAM, role and permissions the recomendation is to initialize the lambda function manually on AWS.1) [Create a Lambda Function using the AWS Console](https://docs.aws.amazon.com/lambda/latest/dg/getting-started-create-function.html)
2) Update function-name in `package.json` with the name of the function you just created:
```
// package.json
...
"scripts": {
...
"update": "aws lambda update-function-code --function-name MyNewLambdaFunctionName --zip-file fileb://dist.zip --publish",
...
}
...
```
3) [Install `aws-cli`](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
4) `npm run deploy` to build, run tests and update your function to the latest code## Run Scripts
### Build
Use webpack to build/index.js:`npm run build`
### Deploy
Build, execute tests in continuous integration mode (bail on failure) and update your Lambda function with the latest code:`npm run deploy`
### Test
##### Run jest tests:`npm run test`
##### Run jest tests in continuous integration mode (hard exit on test failure):
`npm run test:ci`
##### Run Jest tests continuously and watch for changes:
`npm run test:watch`
##### Debug Jest tests with Chrome browser:
1) Insert `debugger` on a line in your test
2) `npm run test:debug`
3) Open Chrome and navigate to about:inspect### Watch
Monitor `src` folder for changes and rebuild when changes occur.`npm run watch`
### Start
Used to be the case that we had to deploy a lambda function to test what would actually happen in a production environment. This is no longer the case, now we can emulate API Gateway and AWS Lambda locally using the [AWS-SAM-CLI](https://github.com/awslabs/aws-sam-cli) from Amazon. The `template.yml` file in the root of the repository is the configuration used by SAM Local (points to code in `build/index.js`).Local Development Prerequisites. Running functions locally with SAM Local requires Docker to be installed and running.
- macOS: [Docker for Mac](https://store.docker.com/editions/community/docker-ce-desktop-mac)
- Windows: [Docker Toolbox](https://download.docker.com/win/stable/DockerToolbox.exe)
- Linux: Check your distro’s package manager (e.g. yum install docker)```
npm install -g aws-sam-local
npm start
```Starts the AWS SAM Local development server on `http://127.0.0.1:3000`. Open `http://127.0.0.1:3000` in your browser to execute your Lambda function.
`Note: You only need to restart SAM CLI if you update your AWS SAM template.`
SAM Local will watch your `build` directory for changes and reload when changes
occur. Be sure to run `npm run watch` to monitor your `src` directory (where you will be writing code) to ensure SAM Local
always has the latest `build/index.js`. Happy coding!#### License
MIT