-
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added more examples for Rust, Go, Java runtimes (#612)
Co-authored-by: Melissa Greenbaum <[email protected]>
- Loading branch information
1 parent
1d12240
commit a6fe411
Showing
35 changed files
with
495 additions
and
39 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
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
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
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
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
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
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
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
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
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
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 @@ | ||
go.sum | ||
bootstrap |
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,5 @@ | ||
module main | ||
|
||
go 1.22.6 | ||
|
||
require github.com/aws/aws-lambda-go v1.47.0 // indirect |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
type MyEvent struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
func HandleRequest(ctx context.Context, event *MyEvent) (*string, error) { | ||
if event == nil { | ||
return nil, fmt.Errorf("received nil event") | ||
} | ||
message := fmt.Sprintf("Hello %s! serverless.tf was here!", event.Name) | ||
return &message, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(HandleRequest) | ||
} |
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 @@ | ||
.gradle/ | ||
build/ |
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,40 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1' | ||
implementation 'org.slf4j:slf4j-nop:2.0.6' | ||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
// Using terraform-aws-lambda module, there is no need to make Zip archive by Gradle. Terraform AWS module will make it for you. | ||
// task buildZip(type: Zip) { | ||
// from compileJava | ||
// from processResources | ||
// into('lib') { | ||
// from configurations.runtimeClasspath | ||
// } | ||
// } | ||
|
||
task copyFiles(type: Copy) { | ||
into("$buildDir/output") | ||
|
||
from sourceSets.main.output | ||
|
||
into('lib') { | ||
from configurations.runtimeClasspath | ||
} | ||
} | ||
|
||
build.dependsOn copyFiles |
19 changes: 19 additions & 0 deletions
19
examples/fixtures/runtimes/java21/src/main/java/example/Handler.java
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 @@ | ||
package example; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.LambdaLogger; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
|
||
import java.util.Map; | ||
|
||
// Handler value: example.Handler | ||
public class Handler implements RequestHandler<Map<String,String>, String>{ | ||
|
||
@Override | ||
public String handleRequest(Map<String,String> event, Context context) | ||
{ | ||
LambdaLogger logger = context.getLogger(); | ||
logger.log("EVENT TYPE: " + event.getClass()); | ||
return "Hello from serverless.tf!!!"; | ||
} | ||
} |
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 @@ | ||
/target | ||
Cargo.lock |
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,20 @@ | ||
[package] | ||
name = "rust-app1" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# Starting in Rust 1.62 you can use `cargo add` to add dependencies | ||
# to your project. | ||
# | ||
# If you're using an older Rust version, | ||
# download cargo-edit(https://github.com/killercup/cargo-edit#installation) | ||
# to install the `add` subcommand. | ||
# | ||
# Running `cargo add DEPENDENCY_NAME` will | ||
# add the latest version of a dependency to the list, | ||
# and it will keep the alphabetic ordering for you. | ||
|
||
[dependencies] | ||
lambda_http = "0.13.0" | ||
|
||
tokio = { version = "1", features = ["macros"] } |
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,30 @@ | ||
use lambda_http::{run, service_fn, tracing, Body, Error, Request, RequestExt, Response}; | ||
|
||
/// 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 | ||
async fn function_handler(event: Request) -> Result<Response<Body>, Error> { | ||
// Extract some useful information from the request | ||
let who = event | ||
.query_string_parameters_ref() | ||
.and_then(|params| params.first("name")) | ||
.unwrap_or("world"); | ||
let message = format!("Hello {who}, this is an AWS Lambda HTTP request. serverless.tf was here!"); | ||
|
||
// Return something that implements IntoResponse. | ||
// It will be serialized to the right response event automatically by the runtime | ||
let resp = Response::builder() | ||
.status(200) | ||
.header("content-type", "text/html") | ||
.body(message.into()) | ||
.map_err(Box::new)?; | ||
Ok(resp) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
tracing::init_default_subscriber(); | ||
|
||
run(service_fn(function_handler)).await | ||
} |
Oops, something went wrong.