Skip to content

Commit

Permalink
chore: add buildcmd integ test for cargo workspace (#7052)
Browse files Browse the repository at this point in the history
* add buildcmd integ test for cargo workspace

* fix test
  • Loading branch information
hawflau committed May 13, 2024
1 parent 4cd3c44 commit e6e698b
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/integration/buildcmd/build_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,12 @@ def rust_parameterized_class(cls):
"function_b",
{"req_id": "99", "msg": "Hello FunctionB"},
),
(
"template_build_method_rust_cargo_workspace.yaml",
"Rust/cargo_workspace/function_b",
None,
{"req_id": "281", "msg": "Hello World B"},
),
],
)(cls)
return cls
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[workspace]
resolver = "2"

members = ["function_a", "function_b"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "function_a"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

lambda_runtime = "0.6.0"
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use lambda_runtime::{run, service_fn, Error, LambdaEvent};

use serde::{Deserialize, Serialize};

/// This is a made-up example. Requests come into the runtime as unicode
/// strings in json format, which can map to any structure that implements `serde::Deserialize`
/// The runtime pays no attention to the contents of the request payload.
#[derive(Deserialize)]
struct Request {
}

/// This is a made-up example of what a response structure may look like.
/// There is no restriction on what it can be. The runtime requires responses
/// to be serialized into json. The runtime pays no attention
/// to the contents of the response payload.
#[derive(Serialize)]
struct Response {
req_id: String,
msg: String,
}

/// This is the main body for the function.
/// Write your code inside it.
/// There are some code example in the following URLs:
/// - https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/examples
/// - https://github.com/aws-samples/serverless-rust-demo/
async fn function_handler(event: LambdaEvent<Request>) -> Result<Response, Error> {
// Prepare the response
let resp = Response {
req_id: "34".to_string(),
msg: "Hello World A".to_string(),
};

// Return `Response` (it will be serialized to JSON automatically by the runtime)
Ok(resp)
}

#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// disable printing the name of the module in every log line.
.with_target(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();

run(service_fn(function_handler)).await
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "function_b"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

lambda_runtime = "0.6.0"
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use lambda_runtime::{run, service_fn, Error, LambdaEvent};

use serde::{Deserialize, Serialize};

/// This is a made-up example. Requests come into the runtime as unicode
/// strings in json format, which can map to any structure that implements `serde::Deserialize`
/// The runtime pays no attention to the contents of the request payload.
#[derive(Deserialize)]
struct Request {
}

/// This is a made-up example of what a response structure may look like.
/// There is no restriction on what it can be. The runtime requires responses
/// to be serialized into json. The runtime pays no attention
/// to the contents of the response payload.
#[derive(Serialize)]
struct Response {
req_id: String,
msg: String,
}

/// This is the main body for the function.
/// Write your code inside it.
/// There are some code example in the following URLs:
/// - https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/examples
/// - https://github.com/aws-samples/serverless-rust-demo/
async fn function_handler(event: LambdaEvent<Request>) -> Result<Response, Error> {
// Prepare the response
let resp = Response {
req_id: "281".to_string(),
msg: "Hello World B".to_string(),
};

// Return `Response` (it will be serialized to JSON automatically by the runtime)
Ok(resp)
}

#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// disable printing the name of the module in every log line.
.with_target(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();

run(service_fn(function_handler)).await
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameters:
Runtime:
Type: String
CodeUri:
Type: String
Handler:
Type: String
Architectures:
Type: String

Resources:

Function:
Type: AWS::Serverless::Function
Properties:
Handler: !Ref Handler
Runtime: !Ref Runtime
CodeUri: !Ref CodeUri
Timeout: 600
Architectures:
- !Ref Architectures
Metadata:
BuildMethod: rust-cargolambda

0 comments on commit e6e698b

Please sign in to comment.