use of software.amazon.awssdk.services.lambda.model.LambdaException in project aws-doc-sdk-examples by awsdocs.
the class DeleteFunction method deleteLambdaFunction.
// snippet-start:[lambda.java2.delete.main]
public static void deleteLambdaFunction(LambdaClient awsLambda, String functionName) {
try {
// Setup an DeleteFunctionRequest
DeleteFunctionRequest request = DeleteFunctionRequest.builder().functionName(functionName).build();
awsLambda.deleteFunction(request);
System.out.println("The " + functionName + " function was deleted");
} catch (LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.lambda.model.LambdaException in project aws-doc-sdk-examples by awsdocs.
the class CreateFunction method createLambdaFunction.
// snippet-start:[lambda.java2.create.main]
public static void createLambdaFunction(LambdaClient awsLambda, String functionName, String filePath, String role, String handler) {
try {
InputStream is = new FileInputStream(filePath);
SdkBytes fileToUpload = SdkBytes.fromInputStream(is);
FunctionCode code = FunctionCode.builder().zipFile(fileToUpload).build();
CreateFunctionRequest functionRequest = CreateFunctionRequest.builder().functionName(functionName).description("Created by the Lambda Java API").code(code).handler(handler).runtime(Runtime.JAVA8).role(role).build();
CreateFunctionResponse functionResponse = awsLambda.createFunction(functionRequest);
System.out.println("The function ARN is " + functionResponse.functionArn());
} catch (LambdaException | FileNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.lambda.model.LambdaException in project aws-doc-sdk-examples by awsdocs.
the class GetAccountSettings method getSettings.
// snippet-start:[lambda.java2.account.main]
public static void getSettings(LambdaClient awsLambda) {
try {
GetAccountSettingsResponse response = awsLambda.getAccountSettings();
System.out.println("Total code size for your account is " + response.accountLimit().totalCodeSize() + " bytes");
} catch (LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.lambda.model.LambdaException in project aws-doc-sdk-examples by awsdocs.
the class ListLambdaFunctions method listFunctions.
// snippet-start:[lambda.java2.list.main]
public static void listFunctions(LambdaClient awsLambda) {
try {
ListFunctionsResponse functionResult = awsLambda.listFunctions();
List<FunctionConfiguration> list = functionResult.functions();
for (FunctionConfiguration config : list) {
System.out.println("The function name is " + config.functionName());
}
} catch (LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.lambda.model.LambdaException in project aws-doc-sdk-examples by awsdocs.
the class LambdaInvoke method invokeFunction.
// snippet-start:[lambda.java2.invoke.main]
public static void invokeFunction(LambdaClient awsLambda, String functionName) {
InvokeResponse res = null;
try {
// Need a SdkBytes instance for the payload
String json = "{\"Hello \":\"Paris\"}";
SdkBytes payload = SdkBytes.fromUtf8String(json);
// Setup an InvokeRequest
InvokeRequest request = InvokeRequest.builder().functionName(functionName).payload(payload).build();
res = awsLambda.invoke(request);
String value = res.payload().asUtf8String();
System.out.println(value);
} catch (LambdaException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations