Skip to content

Commit d7c53b2

Browse files
authored
add support for integration test via GitHub Actions (#913)
1 parent 6bbd1c1 commit d7c53b2

15 files changed

+240
-751
lines changed
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Run integration tests
2+
3+
permissions:
4+
id-token: write
5+
contents: read
6+
7+
on:
8+
workflow_dispatch:
9+
push:
10+
11+
jobs:
12+
run-integration-tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: install Cargo Lambda
16+
uses: jaxxstorm/[email protected]
17+
with:
18+
repo: cargo-lambda/cargo-lambda
19+
platform: linux
20+
arch: x86_64
21+
- name: install Zig toolchain
22+
uses: korandoru/setup-zig@v1
23+
with:
24+
zig-version: 0.10.0
25+
- name: install SAM
26+
uses: aws-actions/setup-sam@v2
27+
with:
28+
use-installer: true
29+
- uses: actions/checkout@v3
30+
- name: configure aws credentials
31+
uses: aws-actions/[email protected]
32+
with:
33+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
34+
role-session-name: ${{ secrets.ROLE_SESSION_NAME }}
35+
aws-region: ${{ secrets.AWS_REGION }}
36+
- name: build stack
37+
run: cd lambda-integration-tests && sam build --beta-features
38+
- name: validate stack
39+
run: cd lambda-integration-tests && sam validate --lint
40+
- name: deploy stack
41+
id: deploy_stack
42+
env:
43+
AWS_REGION: ${{ secrets.AWS_REGION }}
44+
run: |
45+
cd lambda-integration-tests
46+
stackName="aws-lambda-rust-integ-test-$GITHUB_RUN_ID"
47+
echo "STACK_NAME=$stackName" >> "$GITHUB_OUTPUT"
48+
echo "Stack name = $stackName"
49+
sam deploy --stack-name "${stackName}" --parameter-overrides "ParameterKey=SecretToken,ParameterValue=${{ secrets.SECRET_TOKEN }}" "ParameterKey=LambdaRole,ParameterValue=${{ secrets.AWS_LAMBDA_ROLE }}" --no-confirm-changeset --no-progressbar > disable_output
50+
TEST_ENDPOINT=$(sam list stack-outputs --stack-name "${stackName}" --output json | jq -r '.[] | .OutputValue')
51+
echo "TEST_ENDPOINT=$TEST_ENDPOINT" >> "$GITHUB_OUTPUT"
52+
- name: run test
53+
env:
54+
SECRET_TOKEN: ${{ secrets.SECRET_TOKEN }}
55+
TEST_ENDPOINT: ${{ steps.deploy_stack.outputs.TEST_ENDPOINT }}
56+
run: cd lambda-integration-tests && cargo test
57+
- name: cleanup
58+
if: always()
59+
env:
60+
AWS_REGION: ${{ secrets.AWS_REGION }}
61+
STACK_NAME: ${{ steps.deploy_stack.outputs.STACK_NAME }}
62+
run: sam delete --stack-name "${STACK_NAME}" --no-prompts

lambda-integration-tests/Cargo.toml

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
[package]
2-
name = "lambda_integration_tests"
3-
version = "0.5.0"
4-
authors = ["Nicolas Moutschen <[email protected]>"]
5-
edition = "2018"
2+
name = "aws_lambda_rust_integration_tests"
3+
version = "0.1.0"
4+
authors = ["Maxime David"]
5+
edition = "2021"
66
description = "AWS Lambda Runtime integration tests"
77
license = "Apache-2.0"
88
repository = "https://github.com/awslabs/aws-lambda-rust-runtime"
99
categories = ["web-programming::http-server"]
1010
keywords = ["AWS", "Lambda", "API"]
1111
readme = "../README.md"
1212

13-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14-
1513
[dependencies]
16-
lambda_http = { path = "../lambda-http" }
1714
lambda_runtime = { path = "../lambda-runtime" }
18-
lambda-extension = { path = "../lambda-extension" }
19-
serde = { version = "1", features = ["derive"] }
15+
aws_lambda_events = { path = "../lambda-events" }
16+
serde_json = "1.0.121"
2017
tokio = { version = "1", features = ["full"] }
21-
tracing = { version = "0.1", features = ["log"] }
22-
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
18+
serde = { version = "1.0.204", features = ["derive"] }
19+
20+
[dev-dependencies]
21+
reqwest = { version = "0.12.5", features = ["blocking"] }
22+
openssl = { version = "0.10", features = ["vendored"] }
23+
24+
[[bin]]
25+
name = "helloworld"
26+
path = "src/helloworld.rs"
27+
28+
[[bin]]
29+
name = "authorizer"
30+
path = "src/authorizer.rs"

lambda-integration-tests/python/main.py

-4
This file was deleted.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version = 0.1
2+
3+
[default]
4+
[default.build.parameters]
5+
cached = true
6+
parallel = true
7+
8+
[default.validate.parameters]
9+
lint = true
10+
11+
[default.deploy.parameters]
12+
capabilities = "CAPABILITY_IAM"
13+
confirm_changeset = true
14+
s3_bucket = "aws-lambda-rust-runtime-integration-testing"
15+
16+
[default.sync.parameters]
17+
watch = true
18+
19+
[default.local_start_api.parameters]
20+
warm_containers = "EAGER"
21+
22+
[default.local_start_lambda.parameters]
23+
warm_containers = "EAGER"
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::env;
2+
3+
use aws_lambda_events::{
4+
apigw::{ApiGatewayCustomAuthorizerPolicy, ApiGatewayCustomAuthorizerResponse},
5+
event::iam::IamPolicyStatement,
6+
};
7+
use lambda_runtime::{service_fn, tracing, Error, LambdaEvent};
8+
use serde::Deserialize;
9+
use serde_json::json;
10+
11+
#[derive(Deserialize)]
12+
#[serde(rename_all = "camelCase")]
13+
struct APIGatewayCustomAuthorizerRequest {
14+
authorization_token: String,
15+
method_arn: String,
16+
}
17+
18+
#[tokio::main]
19+
async fn main() -> Result<(), Error> {
20+
tracing::init_default_subscriber();
21+
let func = service_fn(func);
22+
lambda_runtime::run(func).await?;
23+
Ok(())
24+
}
25+
26+
async fn func(
27+
event: LambdaEvent<APIGatewayCustomAuthorizerRequest>,
28+
) -> Result<ApiGatewayCustomAuthorizerResponse, Error> {
29+
let expected_token = env::var("SECRET_TOKEN").expect("could not read the secret token");
30+
if event.payload.authorization_token == expected_token {
31+
return Ok(allow(&event.payload.method_arn));
32+
}
33+
panic!("token is not valid");
34+
}
35+
36+
fn allow(method_arn: &str) -> ApiGatewayCustomAuthorizerResponse {
37+
let stmt = IamPolicyStatement {
38+
action: vec!["execute-api:Invoke".to_string()],
39+
resource: vec![method_arn.to_owned()],
40+
effect: aws_lambda_events::iam::IamPolicyEffect::Allow,
41+
condition: None,
42+
};
43+
let policy = ApiGatewayCustomAuthorizerPolicy {
44+
version: Some("2012-10-17".to_string()),
45+
statement: vec![stmt],
46+
};
47+
ApiGatewayCustomAuthorizerResponse {
48+
principal_id: Some("user".to_owned()),
49+
policy_document: policy,
50+
context: json!({ "hello": "world" }),
51+
usage_identifier_key: None,
52+
}
53+
}

lambda-integration-tests/src/bin/extension-fn.rs

-28
This file was deleted.

lambda-integration-tests/src/bin/extension-trait.rs

-88
This file was deleted.

lambda-integration-tests/src/bin/http-fn.rs

-26
This file was deleted.

0 commit comments

Comments
 (0)