-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathInvokeLambdaIT.java
More file actions
40 lines (34 loc) · 1.46 KB
/
InvokeLambdaIT.java
File metadata and controls
40 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package airhacks;
import static org.junit.jupiter.api.Assertions.assertNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.lambda.LambdaClient;
import software.amazon.awssdk.services.lambda.model.InvocationType;
import software.amazon.awssdk.services.lambda.model.InvokeRequest;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.core.SdkBytes;
public class InvokeLambdaIT {
LambdaClient client;
@BeforeEach
public void initClient() {
var credentials = DefaultCredentialsProvider.builder().build();
this.client = LambdaClient.builder()
.credentialsProvider(credentials)
.build();
}
@Test
public void invokeLambdaAsynchronously() {
String json = "{\"user\":\"duke\"}";
SdkBytes payload = SdkBytes.fromUtf8String(json);
InvokeRequest request = InvokeRequest.builder()
.functionName("airhacks_POJOLambda")
.payload(payload)
.invocationType(InvocationType.REQUEST_RESPONSE)
.build();
var response = this.client.invoke(request);
var error = response.functionError();
assertNull(error);
var value = response.payload().asUtf8String();
System.out.println("Function executed. Response: " + value);
}
}