Search in sources :

Example 1 with LambdaException

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);
    }
}
Also used : LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException) DeleteFunctionRequest(software.amazon.awssdk.services.lambda.model.DeleteFunctionRequest)

Example 2 with LambdaException

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);
    }
}
Also used : CreateFunctionResponse(software.amazon.awssdk.services.lambda.model.CreateFunctionResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) CreateFunctionRequest(software.amazon.awssdk.services.lambda.model.CreateFunctionRequest) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FunctionCode(software.amazon.awssdk.services.lambda.model.FunctionCode) FileNotFoundException(java.io.FileNotFoundException) LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException) FileInputStream(java.io.FileInputStream)

Example 3 with LambdaException

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);
    }
}
Also used : GetAccountSettingsResponse(software.amazon.awssdk.services.lambda.model.GetAccountSettingsResponse) LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException)

Example 4 with LambdaException

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);
    }
}
Also used : ListFunctionsResponse(software.amazon.awssdk.services.lambda.model.ListFunctionsResponse) FunctionConfiguration(software.amazon.awssdk.services.lambda.model.FunctionConfiguration) LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException)

Example 5 with LambdaException

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);
    }
}
Also used : InvokeResponse(software.amazon.awssdk.services.lambda.model.InvokeResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) InvokeRequest(software.amazon.awssdk.services.lambda.model.InvokeRequest) LambdaException(software.amazon.awssdk.services.lambda.model.LambdaException)

Aggregations

LambdaException (software.amazon.awssdk.services.lambda.model.LambdaException)5 SdkBytes (software.amazon.awssdk.core.SdkBytes)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 CreateFunctionRequest (software.amazon.awssdk.services.lambda.model.CreateFunctionRequest)1 CreateFunctionResponse (software.amazon.awssdk.services.lambda.model.CreateFunctionResponse)1 DeleteFunctionRequest (software.amazon.awssdk.services.lambda.model.DeleteFunctionRequest)1 FunctionCode (software.amazon.awssdk.services.lambda.model.FunctionCode)1 FunctionConfiguration (software.amazon.awssdk.services.lambda.model.FunctionConfiguration)1 GetAccountSettingsResponse (software.amazon.awssdk.services.lambda.model.GetAccountSettingsResponse)1 InvokeRequest (software.amazon.awssdk.services.lambda.model.InvokeRequest)1 InvokeResponse (software.amazon.awssdk.services.lambda.model.InvokeResponse)1 ListFunctionsResponse (software.amazon.awssdk.services.lambda.model.ListFunctionsResponse)1