-
I tested a simple Exception occurred when calling Error
TestLambda Handlerpackage event;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import software.amazon.lambda.powertools.parameters.ParamManager;
import software.amazon.lambda.powertools.parameters.SSMProvider;
public class LambdaHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
// Parameters
SSMProvider ssmProvider = ParamManager.getSsmProvider();
String value = ssmProvider.get("/my/parameter");
// Response
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
response.setIsBase64Encoded(false);
response.setStatusCode(200);
Map<String, String> headers = Map.of("Content-Type", "application/json");
response.setHeaders(headers);
response.setBody(value);
return response;
}
} build.gradleplugins {
id 'java'
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
}
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
test {
useJUnitPlatform()
}
dependencies {
implementation 'com.amazonaws:aws-lambda-java-core:1.2.1'
implementation 'com.amazonaws:aws-lambda-java-events:3.11.0'
aspect 'software.amazon.lambda:powertools-parameters:1.15.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
}
task packageAllZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
}
}
task packageZip(type: Zip) {
from compileJava
from processResources
}
build.dependsOn packageAllZip Running environment
Build warningI don't know if it's related, the following warning is displayed.
How can I do, help please. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Looks like you are in a test, not running in Lambda. You need to specify the AWS_REGION for your tests: test {
environment "AWS_REGION", "eu-west-1"
} |
Beta Was this translation helpful? Give feedback.
-
An error will occur if I do not set 3 environment variables. If
I can get it correctly with that aws profile in aws cli.
|
Beta Was this translation helpful? Give feedback.
we fixed something in 1.6.1 relative to parameters and client initialization (#1282), not sure how it solves your issue tho... but that's great.