File tree Expand file tree Collapse file tree
examples/basic-lambda-concurrent-s3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " basic-lambda-concurrent-s3"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+ [dependencies ]
7+ aws-config = { version = " 1" , features = [" behavior-version-latest" ] }
8+ aws-sdk-s3 = " 1"
9+ lambda_runtime = { path = " ../../lambda-runtime" , features = [" concurrency-tokio" ] }
10+ serde = { version = " 1" , features = [" derive" ] }
11+ tokio = { version = " 1" , features = [" macros" ] }
Original file line number Diff line number Diff line change 1+ use aws_config:: BehaviorVersion ;
2+ use lambda_runtime:: { service_fn, Error , LambdaEvent } ;
3+ use serde:: { Deserialize , Serialize } ;
4+
5+ #[ derive( Deserialize ) ]
6+ struct Request {
7+ bucket : String ,
8+ key : String ,
9+ body : String ,
10+ }
11+
12+ #[ derive( Serialize ) ]
13+ struct Response {
14+ message : String ,
15+ }
16+
17+ #[ tokio:: main]
18+ async fn main ( ) -> Result < ( ) , Error > {
19+ let config = aws_config:: load_defaults ( BehaviorVersion :: latest ( ) ) . await ;
20+ let s3_client = aws_sdk_s3:: Client :: new ( & config) ;
21+
22+ lambda_runtime:: run_concurrent ( service_fn ( move |event : LambdaEvent < Request > | {
23+ let s3_client = s3_client. clone ( ) ; // cheap clone, no Arc needed
24+ async move {
25+ s3_client
26+ . put_object ( )
27+ . bucket ( & event. payload . bucket )
28+ . key ( & event. payload . key )
29+ . body ( event. payload . body . into_bytes ( ) . into ( ) )
30+ . send ( )
31+ . await ?;
32+ Ok :: < Response , Error > ( Response {
33+ message : "uploaded" . into ( ) ,
34+ } )
35+ }
36+ } ) )
37+ . await
38+ }
You can’t perform that action at this time.
0 commit comments