Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5b9d1a2
Merge pull request #4 from awslabs/main
eduardomourar Apr 18, 2022
d60e1a1
Merge pull request #5 from awslabs/main
eduardomourar Apr 22, 2022
3f5113c
feat(http-server): support make lambda service
eduardomourar Apr 18, 2022
f7fd0ba
chore: make service from right direction
eduardomourar Apr 19, 2022
55b7149
chore: add original repository information
eduardomourar Apr 19, 2022
983563a
chore: add debugging logs
eduardomourar Apr 19, 2022
7043043
chore: set correct response body
eduardomourar Apr 19, 2022
435dcd0
chore: reply with empty body
eduardomourar Apr 19, 2022
a5e17a2
chore: unwrap response
eduardomourar Apr 19, 2022
e1badfe
chore: revert to lambda http v0.5
eduardomourar Apr 19, 2022
746638f
chore: use service from lambda http
eduardomourar Apr 19, 2022
d37fca6
chore: put back response transformation
eduardomourar Apr 19, 2022
2d05423
chore: restrict service future
eduardomourar Apr 20, 2022
0da5b91
chore: use infallible error
eduardomourar Apr 20, 2022
1c45108
chore: implement with opaque future
eduardomourar Apr 20, 2022
fe98731
chore: make request transformation synchronous
eduardomourar Apr 20, 2022
1f80ad6
chore: add lambda test to example service
eduardomourar Apr 20, 2022
7ecc6b7
chore: use types from http library
eduardomourar Apr 20, 2022
e7f4933
chore: recreate uri from raw http path
eduardomourar Apr 21, 2022
f80436d
chore: log api gateway request context
eduardomourar Apr 21, 2022
69cbc44
chore: ignore when raw path is empty
eduardomourar Apr 21, 2022
17f3af6
chore: remove extra debugging logs
eduardomourar Apr 22, 2022
270de97
chore: call service properly by cloning it
eduardomourar Apr 24, 2022
27bb87c
Merge branch 'main' into feat/support-lambda
eduardomourar Apr 26, 2022
2e499e1
Merge branch 'main' into feat/support-lambda
eduardomourar May 2, 2022
a5e05e3
chore: move get_body_as_string to test helpers
eduardomourar May 2, 2022
0637951
chore(http-server): add unit tests
eduardomourar May 2, 2022
16b72c4
Merge branch 'main' into feat/support-lambda
crisidev May 3, 2022
c1f3f80
Merge branch 'main' into feat/support-lambda
eduardomourar May 3, 2022
b1cb817
chore: ensure request extensions are preserved
eduardomourar May 4, 2022
e05b302
chore: use lambda http released version
eduardomourar May 9, 2022
03253be
Merge pull request #6 from awslabs/main
eduardomourar Jun 5, 2022
817bf68
Merge branch 'awslabs:main' into main
eduardomourar Jun 13, 2022
39e8606
Merge branch 'main' into feat/support-lambda
eduardomourar Jun 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rust-runtime/aws-smithy-http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ futures-util = { version = "0.3", default-features = false }
http = "0.2"
http-body = "0.4"
hyper = { version = "0.14", features = ["server", "http1", "http2", "tcp", "stream"] }
lambda_http = "0.5"
mime = "0.3"
nom = "7"
paste = "1"
Expand All @@ -35,9 +36,11 @@ thiserror = "1"
tokio = { version = "1.0", features = ["full"] }
tower = { version = "0.4.11", features = ["util", "make"], default-features = false }
tower-http = { version = "0.3", features = ["add-extension", "map-response-body"] }
tracing = "0.1"

[dev-dependencies]
pretty_assertions = "1"
serde_json = { version = "1", default-features = false, features = ["alloc"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
6 changes: 6 additions & 0 deletions rust-runtime/aws-smithy-http-server/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ run: codegen
doc-open: codegen
cargo doc --no-deps --open

lambda_watch:
cargo lambda watch

lambda_invoke:
cargo lambda invoke bootstrap --data-file pokemon_service/tests/fixtures/example-apigw-request.json

clean:
cargo clean || echo "Unable to run cargo clean"

Expand Down
18 changes: 16 additions & 2 deletions rust-runtime/aws-smithy-http-server/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,32 @@ can be used directly.

`make distclean` can be used for a complete cleanup of all artefacts.

## Run
## On Hyper server

### Run

`cargo run` can be used to start the Pokémon service on
`http://localhost:13734`.

## Test
### Test

`cargo test` can be used to spawn the service and run some simple integration
tests against it.

More info can be found in the `tests` folder of `pokemon_service` package.

## On Lambda

### Run

`make lambda_watch` can be used to start the Pokémon service using the
Lambda emulator provided by https://github.com/cargo-lambda/cargo-lambda.

### Test

`make lambda_invoke` can be used to run some simple request based on a
API Gateway sample payload.

## Benchmarks

Please see [BENCHMARKS.md](/rust-runtime/aws-smithy-http-server/examples/BENCHMARKS.md).
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "A smithy Rust service to retrieve information about Pokémon."
[dependencies]
clap = { version = "3.2.1", features = ["derive"] }
hyper = {version = "0.14", features = ["server"] }
lambda_http = "0.5"
tokio = "1"
tower = "0.4"
tower-http = { version = "0.3", features = ["trace"] }
Expand All @@ -27,3 +28,10 @@ wrk-api-bench = "0.0.7"
# Local paths
aws-smithy-client = { path = "../../../aws-smithy-client/", features = ["rustls"] }
pokemon_service_client = { path = "../pokemon_service_client/" }

[[bin]]
name = "bootstrap"
path = "src/main.rs"

[package.metadata.lambda.env]
RUST_LOG = "smithy_http_tower::dispatch=debug,smithy_http::middleware=debug,aws_smithy_http_server=debug"
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
use std::{net::SocketAddr, sync::Arc};

use aws_smithy_http_server::{AddExtensionLayer, Router};
#[allow(unused_imports)]
use lambda_http::{run as run_on_lambda, RequestExt as _};
use clap::Parser;
use pokemon_service::{empty_operation, get_pokemon_species, get_server_statistics, setup_tracing, State};
use pokemon_service_sdk::operation_registry::OperationRegistryBuilder;
use tower::ServiceBuilder;
use tower_http::trace::TraceLayer;

/// Returns true if it is running on AWS Lambda
pub fn is_lambda_environment() -> bool {
std::env::var("AWS_LAMBDA_RUNTIME_API").is_ok()
}

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
Expand Down Expand Up @@ -49,14 +56,22 @@ pub async fn main() {
.layer(AddExtensionLayer::new(shared_state)),
);

// Start the [`hyper::Server`].
let bind: SocketAddr = format!("{}:{}", args.address, args.port)
.parse()
.expect("unable to parse the server bind address and port");
let server = hyper::Server::bind(&bind).serve(app.into_make_service());
if is_lambda_environment() {
// Start Lambda
let lambda = run_on_lambda(app.into_make_lambda_service());
if let Err(err) = lambda.await {
eprintln!("lambda error: {}", err);
}
} else {
// Start the [`hyper::Server`].
let bind: SocketAddr = format!("{}:{}", args.address, args.port)
.parse()
.expect("unable to parse the server bind address and port");
let server = hyper::Server::bind(&bind).serve(app.into_make_service());

// Run forever-ish...
if let Err(err) = server.await {
eprintln!("server error: {}", err);
// Run forever-ish...
if let Err(err) = server.await {
eprintln!("server error: {}", err);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"body": null,
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"cache-control": "no-cache",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Content-Type": "application/json",
"headerName": "headerValue",
"Host": "gy415nuibc.execute-api.us-east-1.amazonaws.com",
"Postman-Token": "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f",
"User-Agent": "PostmanRuntime/2.4.5",
"Via": "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==",
"X-Forwarded-For": "54.240.196.186, 54.182.214.83",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"httpMethod": "GET",
"isBase64Encoded": false,
"multiValueHeaders": {
"Accept": [
"*/*"
],
"Accept-Encoding": [
"gzip, deflate"
],
"cache-control": [
"no-cache"
],
"CloudFront-Forwarded-Proto": [
"https"
],
"CloudFront-Is-Desktop-Viewer": [
"true"
],
"CloudFront-Is-Mobile-Viewer": [
"false"
],
"CloudFront-Is-SmartTV-Viewer": [
"false"
],
"CloudFront-Is-Tablet-Viewer": [
"false"
],
"CloudFront-Viewer-Country": [
"US"
],
"Content-Type": [
"application/json"
],
"headerName": [
"headerValue"
],
"Host": [
"gy415nuibc.execute-api.us-east-1.amazonaws.com"
],
"Postman-Token": [
"9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f"
],
"User-Agent": [
"PostmanRuntime/2.4.5"
],
"Via": [
"1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)"
],
"X-Amz-Cf-Id": [
"pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A=="
],
"X-Forwarded-For": [
"54.240.196.186, 54.182.214.83"
],
"X-Forwarded-Port": [
"443"
],
"X-Forwarded-Proto": [
"https"
]
},
"multiValueQueryStringParameters": {
"key": [
"value"
]
},
"path": "/stats",
"pathParameters": null,
"queryStringParameters": {
"key": "value"
},
"requestContext": {
"accountId": "xxxxx",
"apiId": "xxxxx",
"domainName": "testPrefix.testDomainName",
"domainPrefix": "testPrefix",
"extendedRequestId": "NvWWKEZbliAFliA=",
"httpMethod": "GET",
"identity": {
"accessKey": "xxxxx",
"accountId": "xxxxx",
"apiKey": "test-invoke-api-key",
"apiKeyId": "test-invoke-api-key-id",
"caller": "xxxxx:xxxxx",
"cognitoAuthenticationProvider": null,
"cognitoAuthenticationType": null,
"cognitoIdentityId": null,
"cognitoIdentityPoolId": null,
"principalOrgId": null,
"sourceIp": "test-invoke-source-ip",
"user": "xxxxx:xxxxx",
"userAgent": "aws-internal/3 aws-sdk-java/1.12.154 Linux/5.4.156-94.273.amzn2int.x86_64 OpenJDK_64-Bit_Server_VM/25.322-b06 java/1.8.0_322 vendor/Oracle_Corporation cfg/retry-mode/standard",
"userArn": "arn:aws:sts::xxxxx:assumed-role/xxxxx/xxxxx"
},
"path": "/stats",
"protocol": "HTTP/1.1",
"requestId": "e5488776-afe4-4e5e-92b1-37bd23f234d6",
"requestTime": "18/Feb/2022:13:23:12 +0000",
"requestTimeEpoch": 1645190592806,
"resourceId": "ddw8yd",
"resourcePath": "/stats",
"stage": "test-invoke-stage"
},
"resource": "/stats",
"stageVariables": null
}
Loading