Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for integration test via GitHub Actions #913

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 62 additions & 0 deletions .github/workflows/run-integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Run integration tests

permissions:
id-token: write
contents: read

on:
workflow_dispatch:
push:

jobs:
run-integration-tests:
runs-on: ubuntu-latest
steps:
- name: install Cargo Lambda
uses: jaxxstorm/[email protected]
with:
repo: cargo-lambda/cargo-lambda
platform: linux
arch: x86_64
- name: install Zig toolchain
uses: korandoru/setup-zig@v1
with:
zig-version: 0.10.0
- name: install SAM
uses: aws-actions/setup-sam@v2
with:
use-installer: true
- uses: actions/checkout@v3
- name: configure aws credentials
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: ${{ secrets.ROLE_SESSION_NAME }}
aws-region: ${{ secrets.AWS_REGION }}
- name: build stack
run: cd lambda-integration-tests && sam build --beta-features
- name: validate stack
run: cd lambda-integration-tests && sam validate --lint
- name: deploy stack
id: deploy_stack
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
cd lambda-integration-tests
stackName="aws-lambda-rust-integ-test-$GITHUB_RUN_ID"
echo "STACK_NAME=$stackName" >> "$GITHUB_OUTPUT"
echo "Stack name = $stackName"
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
TEST_ENDPOINT=$(sam list stack-outputs --stack-name "${stackName}" --output json | jq -r '.[] | .OutputValue')
echo "TEST_ENDPOINT=$TEST_ENDPOINT" >> "$GITHUB_OUTPUT"
- name: run test
env:
SECRET_TOKEN: ${{ secrets.SECRET_TOKEN }}
TEST_ENDPOINT: ${{ steps.deploy_stack.outputs.TEST_ENDPOINT }}
run: cd lambda-integration-tests && cargo test
- name: cleanup
if: always()
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
STACK_NAME: ${{ steps.deploy_stack.outputs.STACK_NAME }}
run: sam delete --stack-name "${STACK_NAME}" --no-prompts
30 changes: 19 additions & 11 deletions lambda-integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
[package]
name = "lambda_integration_tests"
version = "0.5.0"
authors = ["Nicolas Moutschen <[email protected]>"]
edition = "2018"
name = "aws_lambda_rust_integration_tests"
version = "0.1.0"
authors = ["Maxime David"]
edition = "2021"
description = "AWS Lambda Runtime integration tests"
license = "Apache-2.0"
repository = "https://github.com/awslabs/aws-lambda-rust-runtime"
categories = ["web-programming::http-server"]
keywords = ["AWS", "Lambda", "API"]
readme = "../README.md"

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

[dependencies]
lambda_http = { path = "../lambda-http" }
lambda_runtime = { path = "../lambda-runtime" }
lambda-extension = { path = "../lambda-extension" }
serde = { version = "1", features = ["derive"] }
aws_lambda_events = { path = "../lambda-events" }
serde_json = "1.0.121"
tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
serde = { version = "1.0.204", features = ["derive"] }

[dev-dependencies]
reqwest = { version = "0.12.5", features = ["blocking"] }
openssl = { version = "0.10", features = ["vendored"] }

[[bin]]
name = "helloworld"
path = "src/helloworld.rs"

[[bin]]
name = "authorizer"
path = "src/authorizer.rs"
4 changes: 0 additions & 4 deletions lambda-integration-tests/python/main.py

This file was deleted.

23 changes: 23 additions & 0 deletions lambda-integration-tests/samconfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version = 0.1

[default]
[default.build.parameters]
cached = true
parallel = true

[default.validate.parameters]
lint = true

[default.deploy.parameters]
capabilities = "CAPABILITY_IAM"
confirm_changeset = true
s3_bucket = "aws-lambda-rust-runtime-integration-testing"

[default.sync.parameters]
watch = true

[default.local_start_api.parameters]
warm_containers = "EAGER"

[default.local_start_lambda.parameters]
warm_containers = "EAGER"
53 changes: 53 additions & 0 deletions lambda-integration-tests/src/authorizer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use std::env;

use aws_lambda_events::{
apigw::{ApiGatewayCustomAuthorizerPolicy, ApiGatewayCustomAuthorizerResponse},
event::iam::IamPolicyStatement,
};
use lambda_runtime::{service_fn, tracing, Error, LambdaEvent};
use serde::Deserialize;
use serde_json::json;

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct APIGatewayCustomAuthorizerRequest {
authorization_token: String,
method_arn: String,
}

#[tokio::main]
async fn main() -> Result<(), Error> {
tracing::init_default_subscriber();
let func = service_fn(func);
lambda_runtime::run(func).await?;
Ok(())
}

async fn func(
event: LambdaEvent<APIGatewayCustomAuthorizerRequest>,
) -> Result<ApiGatewayCustomAuthorizerResponse, Error> {
let expected_token = env::var("SECRET_TOKEN").expect("could not read the secret token");
if event.payload.authorization_token == expected_token {
return Ok(allow(&event.payload.method_arn));
}
panic!("token is not valid");
}

fn allow(method_arn: &str) -> ApiGatewayCustomAuthorizerResponse {
let stmt = IamPolicyStatement {
action: vec!["execute-api:Invoke".to_string()],
resource: vec![method_arn.to_owned()],
effect: aws_lambda_events::iam::IamPolicyEffect::Allow,
condition: None,
};
let policy = ApiGatewayCustomAuthorizerPolicy {
version: Some("2012-10-17".to_string()),
statement: vec![stmt],
};
ApiGatewayCustomAuthorizerResponse {
principal_id: Some("user".to_owned()),
policy_document: policy,
context: json!({ "hello": "world" }),
usage_identifier_key: None,
}
}
28 changes: 0 additions & 28 deletions lambda-integration-tests/src/bin/extension-fn.rs

This file was deleted.

88 changes: 0 additions & 88 deletions lambda-integration-tests/src/bin/extension-trait.rs

This file was deleted.

26 changes: 0 additions & 26 deletions lambda-integration-tests/src/bin/http-fn.rs

This file was deleted.

Loading
Loading