-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
21,275 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
node_modules | ||
.serverless | ||
|
||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# etc | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm run fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[workspace] | ||
members = ["functions/*"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Rust Serverless Lambda Template | ||
|
||
![Rust](https://img.shields.io/badge/Rust-black?style=for-the-badge&logo=rust&logoColor=#E57324) | ||
![Serverless](https://img.shields.io/badge/Serverless-black?style=for-the-badge&logo=serverless&logoColor=#E57324) | ||
![AWS Lambda](https://img.shields.io/badge/AWS_Lambda-232F3E?style=for-the-badge&logo=amazonaws&logoColor=white) | ||
![NPM](https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white) | ||
|
||
--- | ||
|
||
![Repo Size](https://img.shields.io/github/repo-size/sex-request/rust-serverless-lambda-template) | ||
![Stars](https://img.shields.io/github/stars/sex-request/rust-serverless-lambda-template?style=social) | ||
|
||
This setting used by [This Repository](https://github.com/sex-request/backend) | ||
|
||
## Default Setting | ||
|
||
- Rust | ||
- lambda_http | ||
- tokio | ||
- serde_json | ||
- Serverless | ||
- serverless-rust | ||
- dockerless | ||
- default docker image's rust version is 1.43.1 | ||
- before 1.50 caused compile error | ||
- Using husky | ||
- pre-commit : cargo fmt | ||
|
||
## Should Required Settings | ||
|
||
- [Install aws cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) | ||
- setting `aws configure` | ||
- [serverless-rust](https://www.serverless.com/plugins/serverless-rust) should setting `x86_64-unknown-linux-musl` | ||
- if you use `dockerless` option | ||
|
||
## [ IMPORTANT ] Must Change Here | ||
|
||
- `package.json` line 2 - project name | ||
- `serverless.yml` line 1 - service | ||
- `serverless.yml` line 3 - provider | ||
- `serverless.yml` line 21 - functions | ||
|
||
## Usage | ||
|
||
### Install | ||
|
||
```sh | ||
npm ci && npm run postinstall | ||
``` | ||
|
||
### Test | ||
|
||
```sh | ||
npm run test # cargo test | ||
``` | ||
|
||
### Deploy | ||
|
||
```sh | ||
npm run deploy:dev | ||
npm run deploy:qa | ||
npm run deploy:prod | ||
``` | ||
|
||
### Formatting | ||
|
||
```sh | ||
npm run fmt:install # install rustfmt | ||
npm run fmt # formatting | ||
npm run fmt:check # check lint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "health" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
tokio = { version = "^1", features = ["macros"] } | ||
lambda_http = "^0.4" | ||
serde_json = "^1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use lambda_http::lambda_runtime::Error; | ||
use lambda_http::{handler, lambda_runtime, Context, IntoResponse, Request}; | ||
use serde_json::json; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
lambda_runtime::run(handler(health)).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn health(_: Request, _: Context) -> Result<impl IntoResponse, Error> { | ||
// `serde_json::Values` impl `IntoResponse` by default | ||
// creating an application/json response | ||
Ok(json!({ "message": "OK" })) | ||
} | ||
|
||
#[cfg(test)] | ||
mod main_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn health_handle() { | ||
let request = Request::default(); | ||
let expected = json!({ "message": "OK" }).into_response(); | ||
let response = health(request, Context::default()) | ||
.await | ||
.expect("expected Ok(_) value") | ||
.into_response(); | ||
assert_eq!(response.body(), expected.body()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "index" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
tokio = { version = "^1", features = ["macros"] } | ||
lambda_http = "^0.4" | ||
serde_json = "^1" | ||
utils = { path = "../../utils" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use lambda_http::lambda_runtime::Error; | ||
use lambda_http::{handler, lambda_runtime, Context, Request}; | ||
use serde_json::Value; | ||
use utils::query_from_req; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
lambda_runtime::run(handler(index)).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn index(req: Request, _: Context) -> Result<Value, Error> { | ||
return Ok(query_from_req(req)); | ||
} | ||
|
||
#[cfg(test)] | ||
mod main_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::*; | ||
use lambda_http::http::Request; | ||
use lambda_http::Body; | ||
use serde_json::json; | ||
|
||
#[tokio::test] | ||
async fn without_querystring() { | ||
let req = Request::builder() | ||
.uri("http://localhost") | ||
.body(Body::from(())) | ||
.unwrap(); | ||
|
||
assert_eq!( | ||
index(req, Context::default()) | ||
.await | ||
.expect("expected Ok(_) value"), | ||
json!({}) | ||
) | ||
} |
Oops, something went wrong.