Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tsamaya/lambda-middy
https://github.com/tsamaya/lambda-middy
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tsamaya/lambda-middy
- Owner: tsamaya
- License: mit
- Created: 2021-12-14T18:29:24.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-10T22:07:58.000Z (over 1 year ago)
- Last Synced: 2024-05-02T04:34:34.772Z (7 months ago)
- Language: JavaScript
- Size: 1.3 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lambda-middy
![CircleCI](https://img.shields.io/circleci/build/gh/tsamaya/lambda-middy)
![Codecov](https://img.shields.io/codecov/c/gh/tsamaya/lambda-middy)## Prerequistes
- node 14
- jq (nice to have)## get started
- clone
- npm i## test
### invoke local
```bash
npx serverless invoke local -f hello
{
"message": "👋"
}
```### offline dev
```bash
npm run start:offline
```then
```bash
curl -s http://localhost:3001/dev/hello | jq
{
"message": "👋"
}curl -s "http://localhost:3001/dev/hello?name=andy" | jq
{
"message": "Hello!"
}curl -s "http://localhost:3001/dev/hello?name=error" -i
HTTP/1.1 500 Internal Server Error
access-control-allow-origin: *
x-dns-prefetch-control: off
strict-transport-security: max-age=15552000; includeSubDomains; preload
x-download-options: noopen
x-content-type-options: nosniff
referrer-policy: no-referrer
x-permitted-cross-domain-policies: none
content-type: text/plain; charset=utf-8
cache-control: no-cache
content-length: 16
Date: Wed, 15 Dec 2021 11:35:47 GMT
Connection: keep-alive
Keep-Alive: timeout=5Unexpected error
```## deploy
```bash
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=npm run deploy
```## cleanup
```bash
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=npm run remove
```## notes
without middy
```js
const baseHhandler = async (event) => {
try {
console.log(event);
const { name } = event.queryStringParameters || 'unknown';
const message = greetings(name);
const response = {
statusCode: 200,
body: JSON.stringify({ message }),
};
console.log(response);
return response;
} catch (error) {
console.error(error);
return {
statusCode: 500,
body: JSON.stringify({
error,
}),
};
}
};
```with middy
```js
const { name } = event.queryStringParameters || 'unknown';
const message = greetings(name);
return {
statusCode: 200,
body: JSON.stringify({ message }),
};
};const handler = middy(baseHhandler)
.use(inputOutputLogger())
.use(httpErrorHandler());
```## Contributing
Anyone and everyone is welcome to contribute.
## Issues
Find a bug or want to request a new feature? Please let me know by submitting an issue.
## Licensing
Licensed under the MIT License
A copy of the license is available in the repository's [LICENSE](LICENSE) file.