com.amazonaws.services.lambda.AWSLambdaAsyncClientBuilder Java Examples

The following examples show how to use com.amazonaws.services.lambda.AWSLambdaAsyncClientBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSLambdaAsyncClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * The client returned from a builder.
 * @return client object
 */
@Requires(beans = AWSLambdaConfiguration.class)
@Singleton
AWSLambdaAsync awsLambdaAsyncClient() {
    AWSLambdaAsyncClientBuilder builder = configuration.getBuilder();
    return builder.build();
}
 
Example #2
Source File: LambdaFunctionClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
private void createClient() {
    final Connector connectorConfig = getConnectorConfig();
    final RemoteFunctionConfig remoteFunction = connectorConfig.remoteFunction;

    if (!(remoteFunction instanceof AWSLambda)) {
      throw new IllegalArgumentException("Invalid remoteFunctionConfig argument, must be an instance of AWSLambda");
    }

    int maxConnections = getMaxConnections();
    double priority = getPriority();
    int desiredNumberOfThreads = Math.max(MIN_THREADS_PER_CLIENT, (int) (priority * Service.configuration.LAMBDA_REMOTE_FUNCTION_EXECUTORS));
    int numberOfThreads = Math.min(desiredNumberOfThreads, maxConnections);

    logger.info("Creating Lambda Function Client: {}. CONNECTION_ESTABLISH_TIMEOUT: {}, REQUEST_TIMEOUT: {}, CONNECTION_TTL: {}, "
        + "MIN_THREADS_PER_CLIENT: {}, maxConnections: {}, priority: {}, desiredNumberOfThreads: {}, numberOfThreads: {}",
        connectorConfig.id, CONNECTION_ESTABLISH_TIMEOUT, REQUEST_TIMEOUT, CONNECTION_TTL, MIN_THREADS_PER_CLIENT,
        maxConnections, priority, desiredNumberOfThreads, numberOfThreads);

    asyncClient = AWSLambdaAsyncClientBuilder
        .standard()
        .withRegion(extractRegionFromArn(((AWSLambda) remoteFunction).lambdaARN))
        .withCredentials(getAWSCredentialsProvider())
        .withClientConfiguration(new ClientConfiguration()
            .withMaxConnections(maxConnections)
            .withConnectionTimeout(CONNECTION_ESTABLISH_TIMEOUT)
            .withRequestTimeout(REQUEST_TIMEOUT)
            .withMaxErrorRetry(0)
//            .withClientExecutionTimeout(CLIENT_REQUEST_TIMEOUT)
            .withConnectionTTL(CONNECTION_TTL))
        .withExecutorFactory(() -> Executors.newFixedThreadPool(numberOfThreads))
        .build();
  }
 
Example #3
Source File: AmazonAsyncDockerClientsHolder.java    From spring-localstack with Apache License 2.0 5 votes vote down vote up
@Override
public AWSLambdaAsync awsLambda() {
    return decorateWithConfigsAndBuild(
        AWSLambdaAsyncClientBuilder.standard(),
        LocalstackDocker::getEndpointLambda
    );
}
 
Example #4
Source File: AwsLambdaSinkTask.java    From kafka-connect-aws-lambda with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Map<String, String> map) {
  connectorConfig = new AwsLambdaSinkConnectorConfig(map);
  context.timeout(connectorConfig.getRetryBackoff());
  if (client == null) {
    setClient(AWSLambdaAsyncClientBuilder.standard()
      .withRegion(connectorConfig.getAwsRegion())
      .withCredentials(connectorConfig.getAwsCredentialsProvider())
      .build());
  }
}
 
Example #5
Source File: InvocationClient.java    From kafka-connect-lambda with Apache License 2.0 4 votes vote down vote up
public Builder() {
    this.innerBuilder = AWSLambdaAsyncClientBuilder.standard();
}
 
Example #6
Source File: AWSLambdaConfiguration.java    From micronaut-aws with Apache License 2.0 4 votes vote down vote up
/**
 * @return The builder for the {@link com.amazonaws.services.lambda.AWSLambdaAsync} instance
 */
public AWSLambdaAsyncClientBuilder getBuilder() {
    this.builder.setClientConfiguration(clientConfiguration.getClientConfiguration());
    return builder;
}
 
Example #7
Source File: InvokeLambdaAction.java    From cs-actions with Apache License 2.0 4 votes vote down vote up
/**
 * Invokes an AWS Lambda Function in sync mode using AWS Java SDK
 *
 * @param identity          Access key associated with your Amazon AWS or IAM account.
 *                          Example: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
 * @param credential        Secret access key ID associated with your Amazon AWS or IAM account.
 * @param proxyHost         Optional - proxy server used to connect to Amazon API. If empty no proxy will be used.
 *                          Default: ""
 * @param proxyPort         Optional - proxy server port. You must either specify values for both proxyHost and
 *                          proxyPort inputs or leave them both empty.
 *                          Default: ""
 * @param proxyUsername     Optional - proxy server user name.
 *                          Default: ""
 * @param proxyPassword     Optional - proxy server password associated with the proxyUsername input value.
 *                          Default: ""
 * @param function          Lambda function name to call
 *                          Example: "helloWord"
 * @param qualifier         Optional - Lambda function version or alias
 *                          Example: ":1"
 *                          Default: "$LATEST"
 * @param payload           Optional - Lambda function payload in JSON format
 *                          Example: "{"key1":"value1", "key1":"value2"}"
 *                          Default: null
 * @return                  A map with strings as keys and strings as values that contains: outcome of the action, returnCode of the
 *                          operation, or failure message and the exception if there is one
 */
@Action(name = "Invoke AWS Lambda Function",
        outputs = {
                @Output(Outputs.RETURN_CODE),
                @Output(Outputs.RETURN_RESULT),
                @Output(Outputs.EXCEPTION)
        },
        responses = {
                @Response(text = Outputs.SUCCESS, field = Outputs.RETURN_CODE, value = Outputs.SUCCESS_RETURN_CODE,
                        matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED),
                @Response(text = Outputs.FAILURE, field = Outputs.RETURN_CODE, value = Outputs.FAILURE_RETURN_CODE,
                        matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR)
        }
)
public Map<String, String> execute(
        @Param(value = IDENTITY,   required = true)  String identity,
        @Param(value = CREDENTIAL, required = true, encrypted = true)  String credential,
        @Param(value = REGION,     required = true)  String region,
        @Param(value = PROXY_HOST)                   String proxyHost,
        @Param(value = PROXY_PORT)                   String proxyPort,
        @Param(value = PROXY_USERNAME)               String proxyUsername,
        @Param(value = PROXY_PASSWORD)               String proxyPassword,
        @Param(value = FUNCTION_NAME, required = true) String function,
        @Param(value = FUNCTION_QUALIFIER)           String qualifier,
        @Param(value = FUNCTION_PAYLOAD)             String payload,
        @Param(value = CONNECT_TIMEOUT)              String connectTimeoutMs,
        @Param(value = EXECUTION_TIMEOUT)            String execTimeoutMs) {

    proxyPort = defaultIfEmpty(proxyPort, DefaultValues.PROXY_PORT);
    connectTimeoutMs = defaultIfEmpty(connectTimeoutMs, DefaultValues.CONNECT_TIMEOUT);
    execTimeoutMs = defaultIfBlank(execTimeoutMs, DefaultValues.EXEC_TIMEOUT);
    qualifier = defaultIfBlank(qualifier, DefaultValues.DEFAULT_FUNCTION_QUALIFIER);

    ClientConfiguration lambdaClientConf = AmazonWebServiceClientUtil.getClientConfiguration(proxyHost, proxyPort, proxyUsername, proxyPassword, connectTimeoutMs, execTimeoutMs);

    AWSLambdaAsyncClient client = (AWSLambdaAsyncClient) AWSLambdaAsyncClientBuilder.standard()
            .withClientConfiguration(lambdaClientConf)
            .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(identity, credential)))
            .withRegion(region)
            .build();

    InvokeRequest invokeRequest = new InvokeRequest()
            .withFunctionName(function)
            .withQualifier(qualifier)
            .withPayload(payload)
            .withSdkClientExecutionTimeout(Integer.parseInt(execTimeoutMs));

    try {
        InvokeResult invokeResult = client.invoke(invokeRequest);
        return OutputUtilities.getSuccessResultsMap(new String(invokeResult.getPayload().array()));
    } catch (Exception e) {
        return OutputUtilities.getFailureResultsMap(e);
    }
}